I want to use datetime modul utcfromtimestamp meth

2019-08-05 20:42发布

问题:

I want to use datetime module utcfromtimestamp method but its not work in Ninja-IDE. How I can solve my problem?

My code:

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

And Ninja-IDE 2.3 writes this error message:

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

I installed Python 3.4 and setup the path in preferences.

回答1:

You named your file datetime.py, and Python imported that instead of the standard library datetime:

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

So the first datetime is your module, the second datetime a global in your module that references itself, and your module doesn't itself have a utcfromtimestamp global.

Rename your file to something else.