[New-bugs-announce] [issue5239] time.strptime("2009", "%Y") raises a value error
Ezio Melotti
report at bugs.python.org
Fri Feb 13 02:46:35 CET 2009
New submission from Ezio Melotti <ezio.melotti at gmail.com>:
On Py3 strptime("2009", "%Y") fails:
>>> strptime("2009", "%Y")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.0/_strptime.py", line 454, in _strptime_time
return _strptime(data_string, format)[0]
File "/usr/local/lib/python3.0/_strptime.py", line 325, in _strptime
(data_string, format))
ValueError: time data '2009' does not match format '%Y'
but non-ascii numbers are supported elsewhere:
>>> int("2009")
2009
>>> re.match("^\d{4}$", "2009").group()
'2009'
The problem seems to be at the line 265 of _strptime.py:
return re_compile(self.pattern(format), IGNORECASE | ASCII)
The ASCII flag prevent the regex to work properly with '2009':
>>> re.match("^\d{4}$", "2009", re.ASCII)
>>>
I tried to remove the ASCII flag and it worked fine.
On Py2.x the problem is the same:
>>> strptime(u"2009", "%Y")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.5/_strptime.py", line 330, in strptime
(data_string, format))
ValueError>>>
>>> int(u"2009")
2009
>>> re.match("^\d{4}$", u"2009")
Here there's probably to add the re.UNICODE flag at the line 265 (untested):
return re_compile(self.pattern(format), IGNORECASE | UNICODE)
in order to make it work:
>>> re.match("^\d{4}$", u"2009", re.U).group()
u'\uff12\uff10\uff10\uff19'
----------
messages: 81847
nosy: ezio.melotti
severity: normal
status: open
title: time.strptime("2009", "%Y") raises a value error
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5239>
_______________________________________
More information about the New-bugs-announce
mailing list