OT - strptime problems

w2k, py251, wxpy2871-ansi

It seems
- strptime() needs some locale initialization with the side effect that
the language plays a role (août : French, August : German).
- the unicode variant fails !? bug/issue with the "û" ? I did not investigate
further.

>>> import locale
>>> locale.setlocale(locale.LC_ALL, '')
French_Switzerland.1252
>>> locale.getlocale()
('French_Switzerland', '1252')
>>> import time
>>> d = '16 août 2005'
>>> fmt = '%d %b %Y'
>>> time.strptime(d,fmt)
(2005, 8, 16, 0, 0, 0, 1, 228, -1)
>>> #but
>>> time.strptime('16 August 2005', fmt)
Traceback (most recent call last):
   File "<psi last command>", line 1, in <module>
   File "c:\python25\lib\_strptime.py", line 331, in strptime
     (data_string, format))
ValueError: time data did not match format: data=16 August 2005 fmt=%d %b %Y
>>> time.strptime('16. August 2005', fmt)
Traceback (most recent call last):
   File "<psi last command>", line 1, in <module>
   File "c:\python25\lib\_strptime.py", line 331, in strptime
     (data_string, format))
ValueError: time data did not match format: data=16. August 2005 fmt=%d %b %Y
>>> ud = unicode(d, 'cp1252')
>>> ufmt = unicode(fmt, 'cp1252')
>>> time.strptime(ud, ufmt)
C:\Python25\lib\_strptime.py:369: UnicodeWarning: Unicode equal comparison failed
to convert both arguments to Unicode - interpreting them as being unequal
   month = locale_time.a_month.index(found_dict['b'].lower())
Traceback (most recent call last):
   File "<psi last command>", line 1, in <module>
   File "c:\python25\lib\_strptime.py", line 369, in strptime
     month = locale_time.a_month.index(found_dict['b'].lower())
ValueError: list.index(x): x not in list

Workaround (?): Splitting the date and building its own struct_time with the
help of a dictionary like (in French)
{'janvier': 1,
  'février': 2,
  'mars': 3,
  'avril': 4,
  'mai':, 5,
  'juin': 6,
  'juillet': 7,
  'août': 8,
  'septembre': 9,
  'octobre': 10,
  'novembre': 11,
  'décembre': 12}

Jean-Michel Fauth, Switzerland