PySide QApplication打破datetime.strptime()月识别

时间:2016-07-11 00:46:52

标签: python datetime pyside strptime qapplication

我使用datetime.strptime()来获取一个月的月份数,用英文写成。我想将它与一些PySide Qt接口结合使用。但是,一旦启动QApplication,月份识别似乎就会中断。

最小工作示例(我打印的语言环境表明它没有改变):

import sys, datetime

from PySide.QtCore import *
from PySide.QtGui import *

import locale

print(locale.getlocale())
full_date = 'February'
print(datetime.datetime.strptime(full_date,'%B'))

输出:

('en_US', 'UTF-8')
1900-02-01 00:00:00

现在,当我启动QApplication并执行相同操作时:

import sys, datetime

from PySide.QtCore import *
from PySide.QtGui import *

import locale

qt_app = QApplication(sys.argv)

print(locale.getlocale())
full_date = 'February'
print(datetime.datetime.strptime(full_date,'%B'))

输出:

('en_US', 'UTF-8')
Traceback (most recent call last):
  File "my_timedate.py", line 12, in <module>
    print(datetime.datetime.strptime(full_date,'%B'))
  File "/usr/lib/python3.5/_strptime.py", line 510, in _strptime_datetime
    tt, fraction = _strptime(data_string, format)
  File "/usr/lib/python3.5/_strptime.py", line 343, in _strptime
    (data_string, format))
ValueError: time data 'February' does not match format '%B'

发生了什么事?为什么在启动QApplication后它会停止工作?

0 个答案:

没有答案