python datetime.strptime AttributeError

时间:2013-01-30 20:21:17

标签: python datetime

import datetime

print datetime.strptime("00", "%y").year

我希望能够将“00”传递给datetime.strptime并接收“2000”作为输出。但是,当我运行代码时,我不断收到此错误: AttributeError:'module'对象没有属性'strptime'

1 个答案:

答案 0 :(得分:3)

直接在datetime模块的级别找不到

strptime。它是datetime模块中datetime类型的类方法,因此:

print datetime.datetime.strptime("00", "%y").year