2015-01-21 35 views
0

我想使用datetime模块utcfromtimestamp方法,但它在Ninja-IDE中不起作用。我如何解决我的问题?我想使用日期时间模块utcfromtimestamp方法,但它不能在忍者IDE中工作

我的代码:

#-*- coding: utf-8 -*- 
import datetime 
print (datetime.datetime.utcfromtimestamp(130130301)) 

而且忍者IDE 2.3中写入此错误消息:

File "C:\Users\test\Desktop\datetime.py", line 3, in <module> 
    print (datetime.datetime.utcfromtimestamp(130130301)) 
AttributeError: 'module' object has no attribute 'utcfromtimestamp' 

我安装了Python 3.4和设置偏好的路径。

+0

阅读[名称遮蔽陷阱](http://python-notes.curiousefficiency.org/en/latest/python_concepts/import_traps.html#the-name-shadowing-trap) – jfs 2015-01-21 12:49:54

回答

4

您将文件命名为datetime.py,和Python进口的,而不是标准库datetime

File "C:\Users\test\Desktop\datetime.py", line 3, in <module> 
#       ^^^^^^^^ 

所以第一个datetime是你的模块,第二datetime你的模块是引用自身,以及在全球的模块本身并没有全局的utcfromtimestamp

将文件重命名为其他内容。

相关问题