无法在python中“import time”,获取“AttributeError:struct\u time”如何解决?

2024-09-30 06:30:11 发布

您现在位置:Python中文网/ 问答频道 /正文

在雪豹上运行python,我不能导入'time'模块。在ipython工作。没有加载任何.pythonrc文件。使用同一个解释器“导入时间”的脚本运行良好。不知道如何解决这个问题。有人有主意吗?在

[wiggles@bananas ~]$ 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
>>> 
[wiggles@bananas ~]$ 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]: 

Tags: orforobjecttimelicensemoretypeipython
1条回答
网友
1楼 · 发布于 2024-09-30 06:30:11

查找名为时间.py. 看起来Python导入的不是标准库中的:

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

解决方案是将该文件重命名为除“时间.py". 在

顺便说一下,您可以通过打开Python REPL并键入以下内容来找到有问题的文件的路径。在

^{pr2}$

或者

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

相关问题 更多 >

    热门问题