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


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
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3