老师来看看为什么会报错
来源:2-9 datetime模块之时间转换
德德德jak
2019-04-24 22:53:38
ds = '2018/10/3T13:42:09' ds_t = datetime.strptime(ds, '%Y/%m/%dT%H:%M:%S') print(ds_t)
提示第二行报错:
Traceback (most recent call last):
File "E:/Python-project/Python函数与模块/datetime模块/datetime1.py", line 17, in <module>
ds_t = datetime.strptime(ds, '%Y/%m/%dT%H:%M:%S')
File "E:\Python3.71\lib\_strptime.py", line 15, in <module>
import calendar
File "E:\Python3.71\lib\calendar.py", line 50, in <module>
class _localized_month:
File "E:\Python3.71\lib\calendar.py", line 52, in _localized_month
_months = [datetime.date(2001, i+1, 1).strftime for i in range(12)]
File "E:\Python3.71\lib\calendar.py", line 52, in <listcomp>
_months = [datetime.date(2001, i+1, 1).strftime for i in range(12)]
AttributeError: module 'datetime' has no attribute 'date'
Process finished with exit code 1
1回答
时间,
2019-04-25
同学,你好,同学可以看一下是不是在导模块的时候出了问题或者是文件命名出了问题,在老师这运行是没有问题的,可以正常输出结果。
正确代码如下:
from datetime import datetime ds = '2018/10/3T13:42:09' ds_t = datetime.strptime(ds, '%Y/%m/%dT%H:%M:%S') print(ds_t) # 2018-10-03 13:42:09
如果我的回答解决了您的疑惑,请采纳!祝学习愉快~~~~
相似问题