Python 类型错误 : 'module' object is not callable

标签 python linux time module

我在我的 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 模块。将名称更改为不同的名称 - 即。 时间测试.py

关于Python 类型错误 : 'module' object is not callable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41294768/

相关文章:

linux - 将选定的文本发送到节日

if-statement - 如何在谷歌表格中将分钟转换为小时?

javascript - 简化方法以确保时间格式正确

python - 使用 python 识别列表中元组长度为 0 的最佳方法是什么

python - Linux 中 Python 父进程和 C 子进程之间的通信

python - 使用 Ctrl-C 退出 tkinter 应用程序并捕获 SIGINT

javascript - 一段时间后暂停闪光

python - HTCondor 输出文件 : obtain created directory

c++ - Qt 和 openGL 的 gluPerspective 等价物

linux - 在 postgres 9.4 中使用触发器执行外部程序