2010-10-22 25 views
4

在Snow Leopard上運行python,我無法導入'時間'模塊。在ipython中工作。沒有任何正在加載的.pythonrc文件。使用相同解釋器的「輸入時間」的腳本運行良好。不知道如何解決這個問題。任何人有想法?不能在python中導入時間,得到'AttributeError:struct_time'如何解決?

[[email protected] ~]$ python2.6 
Python 2.6.6 (r266:84292, Sep 1 2010, 14:27:13) 
[GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import time 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "time.py", line 4, in <module> 
    t = now.strftime("%d-%m-%Y-%H-%M") 
AttributeError: struct_time 
>>> 
[[email protected] ~]$ ipython-2.6 
Python 2.6.6 (r266:84292, Sep 1 2010, 14:27:13) 
Type "copyright", "credits" or "license" for more information. 

IPython 0.10 -- An enhanced Interactive Python. 
?   -> Introduction and overview of IPython's features. 
%quickref -> Quick reference. 
help  -> Python's own help system. 
object? -> Details about 'object'. ?object also works, ?? prints more. 

In [1]: import time 

In [2]: 

回答

8

查找名爲time.py的文件。它看起來像Python是導入一個,而不是從標準庫中的一個:

File "time.py", line 4, in <module> 

解決的辦法是重新命名不是「time.py」等文件的東西。

順便說一下,您可以通過打開Python REPL並鍵入來找到違規文件的路徑。

In [1]: import time  
In [2]: time.__file__ 

In [3]: time  # This shows the path as part of the repr 
+0

就是這樣,感謝您的快速反應。我有一個隨機腳本,我在幾天前測試了我當前的工作目錄中的time.py。移動它解決了這個問題。 – wiggles 2010-10-22 22:00:39

相關問題