2010-10-22 26 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

相关问题