Warum funktioniert das in der Python IDLE-Shell, aber nicht, wenn ich es als Python-Skript an der Eingabeaufforderung ausführe?
Dies funktioniert in der Python 3.3.2-Shell
In der Python 3.3.2-Shell>>> import datetime
>>> print(datetime.datetime.utcnow())
2013-07-09 19:40:32.532341
Das ist großartig! Ich schrieb dann eine einfache Textdatei mit dem Namen "datetime.py"
Innerhalb von Datetime.py#Date time
import datetime
print(datetime.datetime.utcnow())
#Prints GMT, which is named Universal Coordinated Time
# Which is UTC because in French it's something like
# Universahl Tyme Coordinatay
#Outputs something like 2013-07-09 15:15:19.695531
Nachweis, dass die Datei existiertC:\Python33\myscripts>ls
__pycache__ ex1.out ex2.out ex3.py helloworld.py read1.py
datetime.py ex1.py ex2.py first.py pythonintoimportexport.py test.py
Hier wird es mysteriös!
C:\Python33\myscripts>python datetime.py
Traceback (most recent call last):
File "datetime.py", line 2, in <module>
import datetime
File "C:\Python33\myscripts\datetime.py", line 3, in <module>
print(datetime.datetime.utcnow())
AttributeError: 'module' object has no attribute 'utcnow'
FrageWarum funktioniert derselbe Code in der Python-Shell, aber nicht, wenn er als Skript ausgeführt wird?