Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does Python store German and Spanish (and other?) time format strings as %T in the locale module?
    primarykey
    data
    text
    <p>I'm writing a test for a program that will be used in multiple locales. While running the test in German, i got the error</p> <pre><code>Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; File "/usr/local/lib/python2.7/_strptime.py", line 454, in _strptime_time return _strptime(data_string, format)[0] File "/usr/local/lib/python2.7/_strptime.py", line 317, in _strptime (bad_directive, format)) ValueError: 'T' is a bad directive in format '%T' </code></pre> <p>Digging into this, i discovered that using <code>locale.nl_langinfo(locale.T_FMT)</code> while in German or Spanish (and potentially other languages) produces the format string <code>'%T'</code>. This is not recognized in the <a href="http://docs.python.org/library/time.html#time.strftime" rel="nofollow noreferrer"><code>time</code> module</a>. </p> <p>The documentation on <code>locale</code> at <a href="http://docs.python.org/library/locale.html" rel="nofollow noreferrer">python.org</a> doesn't mention anything about returning <code>'%T'</code>. The only reference to <code>'%T'</code> i could find anywhere is in a response to <a href="https://stackoverflow.com/q/2507726/534346">a separate StackOverflow question</a>. From that post and context, i'm assuming <code>'%T'</code> is shorthand for <code>'%H:%M:%S'</code>.</p> <p>My question is, how do i handle the locales for which <code>locale</code> will return <code>'%T'</code> for its format string without doing something like</p> <pre><code>if fmt_str == '%T': fmt_str = '%H:%M:%S' </code></pre> <p>to handle those cases?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload