strptime gives "unconverted data remains" for non en_US locale

Bug #993096 reported by Eric Rasche
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
notify-python (Ubuntu)
New
Undecided
Unassigned

Bug Description

This code:

#!/usr/bin/env python
import pynotify
import time
import datetime
c='5/1/12 1:15 PM'
print c
dt = time.strptime(c, "%d/%m/%y %H:%M %p")

produces:

5/1/12 1:15 PM
Traceback (most recent call last):
  File "tmp.py", line 9, in <module>
    dt = time.strptime(c, "%d/%m/%y %H:%M %p")
  File "/usr/lib/python2.7/_strptime.py", line 454, in _strptime_time
    return _strptime(data_string, format)[0]
  File "/usr/lib/python2.7/_strptime.py", line 328, in _strptime
    data_string[found.end():])
ValueError: unconverted data remains: PM
Removing the import pynotify,

#!/usr/bin/env python
import time
import datetime
c='5/1/12 1:15 PM'
print c
dt = time.strptime(c, "%d/%m/%y %H:%M %p")

causes no error.

It appears to be as a result of a non en_US locale. My locale is currently set to nb_NO.UTF-8. Setting this to en_US.UTF-8 fixes the issue.

Revision history for this message
Eric Rasche (rasche-eric) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.