python文件名与module名冲突,出错'module' object has no attribute 'strftime'

时间:2015-10-31 00:14:05   收藏:0   阅读:2767

import
time print time.strftime(%Y%m%d%H%M%S)

以上小程序命名为time.py

运行时出现错误提示:

print time.strftime(‘%Y%m%d%H%M%S‘)

AttributeError: ‘module‘ object has no attribute ‘strftime‘

 

确认了strftime确实是time的函数后,还以为这是一个bug呢

然后直接用console运行以上代码,发现能得出正确的结果,说明代码没问题,那就可能是名字的问题了,想到这里才猛然发现 import的module是time,而我给这个python文件命名的也是time,估计是冲突了。

把自己写的试验程序名字由time.py改成别的后再试果然就运行正常了。

 

原文:http://www.cnblogs.com/myTechBlog-hyh/p/4924614.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!