[英]datetime.strptime doesn't work in PyQt4 QtGui.QWidget inherited class
For example I have this simple class: 例如,我有这个简单的类:
from PyQt4 import QtGui, QtCore
import sys
from datetime import datetime
print datetime.strptime('Wed, 06-Feb-2014 12:05:12', '%a, %d-%b-%Y %H:%M:%S')
class Application(QtGui.QWidget):
def __init__(self):
super(Application, self).__init__()
print datetime.strptime('Wed, 06-Feb-2014 12:05:12', '%a, %d-%b-%Y %H:%M:%S')
def main():
app = QtGui.QApplication(sys.argv)
ex = Application()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
When I run it I have the following output: 当我运行它时,我有以下输出:
2014-02-06 12:05:12
Traceback (most recent call last):
File "vkPlayListSync.py", line 23, in <module>
main()
File "vkPlayListSync.py", line 18, in main
ex = Application()
File "vkPlayListSync.py", line 12, in __init__
print datetime.strptime('Wed, 06-Feb-2014 12:05:12', '%a, %d-%b-%Y %H:%M:%S')
File "/usr/lib/python2.7/_strptime.py", line 325, in _strptime
(data_string, format))
ValueError: time data 'Wed, 06-Feb-2014 12:05:12' does not match format '%a, %d-%b-%Y %H:%M:%S'
so the first line with strptime
, but the second call form the class __init()__
method throws error. 因此,第一行使用
strptime
,但是第二次从类__init()__
方法的调用引发错误。 I have not enough experience in Python and PyQt, so can't understand how to fix this. 我对Python和PyQt的经验不足,因此无法理解如何解决。 And I haven't found the answer here on stackoverflow or in google.
而且我还没有在stackoverflow或google中找到答案。
QApplication
startup is altering your locale such that 'Wed, 06-Feb-2014 12:05:12'
is no longer a valid date (ie the weekday and month names are in another language). QApplication
启动会更改您的区域设置,以使'Wed, 06-Feb-2014 12:05:12'
不再是有效日期(即,工作日和月份名称使用另一种语言)。 Try running your application with LC_ALL="C"
. 尝试使用
LC_ALL="C"
运行您的应用程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.