Re: time.strptime() for different languages
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: time.strptime() for different languages

From: Adam Monsen <haircut@gmail.com>
Date: Thu Sep 01 2005 - 03:08:04 CEST

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/
Received on Thu Sep 29 18:11:35 2005