time.strptime() for different languages

Adam Monsen haircut at gmail.com
Wed Aug 31 21:08:04 EDT 2005


Strange, but I can't figure out how to switch back to the default
locale.

>>> import locale, datetime, time
>>> locale.setlocale(locale.LC_ALL, 'nl_NL')
'nl_NL'
>>> date = '10 augustus 2005 om 17:26'
>>> time.strptime(date, "%d %B %Y om %H:%M")
(2005, 8, 10, 17, 26, 0, 2, 222, -1)
>>> locale.setlocale(locale.LC_ALL, '')
'en_US.UTF-8'
>>> date = '10 August 2005 at 17:26'
>>> time.strptime(date, "%d %B %Y at %H:%M")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.4/_strptime.py", line 292, in strptime
    raise ValueError("time data did not match format:  data=%s  fmt=%s"
%
ValueError: time data did not match format:  data=10 August 2005 at
17:26  fmt=%d %B %Y at %H:%M


Also, locale.resetlocale() throws locale.Error (I saw some open bugs on
this).

Ugh! Is this stuff broken or is it just me?

-- 
Adam Monsen
http://adammonsen.com/




More information about the Python-list mailing list