【问题标题】:Python TypeError: 'module' object is not callablePython TypeError:“模块”对象不可调用
【发布时间】:2017-05-08 18:22:05
【问题描述】:

我在我的 Mac 上以 IDLE 运行一段代码,它运行良好。但是当我尝试从命令行在 linux 机器上运行相同的代码时,它给了我这个错误:

Traceback (most recent call last):
  File "time.py", line 1, in <module>
    import time

File "/home/ugrad/user/time.py", line 3, in <module>

t1 = time.time()

TypeError: 'module' object is not callable

代码如下:

import time

t1 = time.time()
size = 10000000
for i in range(size):
    a = i
    a += 100
    a *= 35
    val = (a == 839248637)
t2 = time.time()
res = t2-t1
print(res)

我在这里做错了什么?

【问题讨论】:

  • 您将文件命名为time.py,所以现在import time 加载您的文件而不是Python time 模块。

标签: python linux time module


【解决方案1】:

您将文件命名为time.py,所以现在import time 加载您的文件而不是Python time 模块。将名称更改为不同的 - 即。 time-test.py

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-17
    • 2014-09-21
    • 2011-05-30
    • 2021-11-22
    • 2017-01-12
    相关资源
    最近更新 更多