简体   繁体   中英

Python TypeError: 'module' object is not callable

I run a piece of code on my mac in IDLE and it works fine. But when I tried to run the same code on a linux machine from the command line it gave me this error:

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

here is the code:

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)

What am I doing wrong here?

You named your file time.py so now import time loads your file instead Python time module. Change name to different - ie. time-test.py

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM