[Python] Python: Why does import time not work for time() but works for time.sleep()?

Discussão em 'Python' iniciado por Stack, Agosto 19, 2025.

  1. Stack

    Stack Membro Participativo

    If I use from time import time, the Python 2.7.3 does not recognize time.sleep(60). But if I use import time, then Python does not recognize t=time(). Why does this happen? Is there any way I can use time() and time.sleep(x) in the same program?

    from time import time
    #import time

    intervalInMinute = 1
    t = time()
    while 1:
    time.sleep(60)


    The kind of error I get is:


    Traceback (most recent call last): File "myProg.py", line 9, in time.sleep(60) AttributeError: 'builtin_function_or_method' object has no attribute 'sleep'
    ​

    Continue reading...

Compartilhe esta Página