python文件名与module名冲突,出错'module' object has no attribute 'strftime'
来源:互联网 发布:机器人编程入门视频 编辑:程序博客网 时间:2024/05/22 03:41
刚刚写了一个获取时间的小程序:
time.py
#!/usr/bin/python#coding=utf-8__author__ = 'cy'import timeprint "time.time(): %f " % time.time()print time.localtime(time.time())print time.asctime(time.localtime(time.time()))print time.strftime('%Y%m%d%H%M%S')
运行时出现错误提示:
……
AttributeError: ‘module‘ object has no attribute ‘strftime’
dir(time)确认了strftime确实是time的函数后,直接用console运行以上代码,发现能得出正确的结果,说明代码没问题,那就可能是名字的问题了,想到这里才突然发现 import的module是time,而我给这个python文件命名的也是time,看了下文件所在目录,果然有一个time.pyc。
然后把自己写的小程序名字由time.py改成ttime.py,删除掉time.pyc后再运行果然就运行正常了。
0 0
- python文件名与module名冲突,出错'module' object has no attribute 'strftime'
- python文件名不要跟模块名相同,报错AttributeError: 'module' object has no attribute 'Differ'
- tensorflow提示出错'module' object has no attribute 'pack'
- tensorflow提示出错'module' object has no attribute 'pack'
- [Python]attributeError:'module' object has no attribute 'dump'
- [python错误]builtins.AttributeError: 'module' object has no attribute 'request'
- python运行不了 AttributeError: module object has no attribute getdefaultlocale
- Python基础学习-'module' object has no attribute 'urlopen'解决方法
- python AttributeError: 'module' object has no attribute 'setdefaultencoding'
- python运行不了 AttributeError: module object has no attribute getdefaultlocale
- python AttributeError: 'module' object has no attribute 'dumps'解决办法
- Python AttributeError: 'module' object has no attribute xxxx
- 关于Python的:'module' object has no attribute 'inet_pton'问题解决
- Python 【精】AttributeError: 'Module' object has no attribute 'STARTF_USESHOWINDOW'
- Python AttributeError: ‘module’ object has no attribute ‘A’
- AttributeError: 'module' object has no attribute 'face' 问题解决 opencv+python
- python 错误解析 AttributeError: 'module' object has no attribute 'dumps'
- 【python】AttributeError: 'module' object has no attribute 'HTTPSConnection'
- springmvc处理静态资源
- LeetCode:419. Battleships in a Board
- 【沟通分享】每天沟通15分钟
- C程序结构--静心梳理,从新开始
- leetcode 496. Next Greater Element I
- python文件名与module名冲突,出错'module' object has no attribute 'strftime'
- View Controller Transition:京东加购物车效果
- 关于丢失表空间数据文件的处理方式
- 【Java】通过JSONObject获取数据库查询结果
- iOS真机与模拟器
- 大型电商网站系统架构演变过程
- 求100的阶乘,大神请路过。。。。
- windows上面装node但是npm一直查不出版本号
- UML学习