例如我有这个简单的类:
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()
当我运行它时,我有以下输出:
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'
所以第一行带有strptime
,但第二个调用形式的类__init()__
方法会引发错误。我在 Python 和 PyQt 方面没有足够的经验,所以无法理解如何解决这个问题。而且我还没有在 stackoverflow 或谷歌上找到答案。