问题
这段代码
#!/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")
生产
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
删除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")
删除错误。
5/1/12 1:15 PM
为什么?!!?!
蟒蛇版本
Python 2.7.2+(默认,2011 年 10 月 4 日,20:06:09)[GCC 4.6.1] on linux2
pynotify。文件
我添加了打印调用pynotify.__file__
和datetime.__file__
/usr/lib/python2.7/lib-dynload/datetime.so
/usr/lib/python2.7/dist-packages/gtk-2.0/pynotify/__init__.pyc
5/1/12 1:15 PM
Traceback (most recent call last):
File "a.py", line 11, 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
数据库
5/1/12 1:15 PM
> /usr/lib/python2.7/_strptime.py(324)_strptime()
-> found = format_regex.match(data_string)
(Pdb) format
'%d/%m/%y %H:%M %p'
(Pdb) continue
> /usr/lib/python2.7/_strptime.py(329)_strptime()
-> if len(data_string) != found.end():
(Pdb) continue
> /usr/lib/python2.7/_strptime.py(331)_strptime()
-> raise ValueError("unconverted data remains: %s" %
(Pdb) len(data_string)
14
(Pdb) found.end()
12
(Pdb) found.group(0)
'5/1/12 1:15 '
似乎'%d/%m/%y %H:%M %p'
没有捕获所有“5/1/12 1:15 PM”