I am learning Python on my own. Now I have encountered some problems. Below is my code which copy from the video who running well.
import datetime
print(type(datetime))
d1 = datetime.datetime.now()
print(d1)
when I running the code using Pycharm & sublime I got error. Below is the error information of sublime
<class 'module'>
Traceback (most recent call last):
File "D:\programming\python\datetime.py", line 1, in <module>
import datetime
File "D:\programming\python\datetime.py", line 4, in <module>
d1 = datetime.datetime.now()
AttributeError: module 'datetime' has no attribute 'now'
below is the error information of pycharm
D:\programming\python\venv\Scripts\python.exe C:\Program Files\JetBrains\PyCharm 2018.1.2\helpers\pydev\pydevconsole.py" 63029 63030
<class 'module'>
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm 2018.1.2\helpers\pydev\pydevconsole.py", line 4, in <module>
from _pydev_imps._pydev_saved_modules import thread
File "C:\Program Files\JetBrains\PyCharm 2018.1.2\helpers\pydev\_pydev_imps\_pydev_saved_modules.py", line 21, in <module>
import xmlrpc.client as xmlrpclib
File "D:\programming\Anoconda3\lib\xmlrpc\client.py", line 134, in <module>
from datetime import datetime
File "D:\programming\python\datetime.py", line 4, in <module>
d1 = datetime.datetime.now()
AttributeError: module 'datetime' has no attribute 'now'
Process finished with exit code 1
This code running well under IDLE and cmd. And it's running well when I just coding print(type(datetime))
, but print double times type of datetime.
I don't know how to do, please give me some advice. Thanks.
from datetime import datetime
instead ofimport datetime
ordatetime.datetime.now()
instead ofdatetime.now()
as provided here. – Exasperationdatetime
in the file name, the problem is fixed. – Neoclassic