Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: AttributeError: 'builtin_function_or_method' object has no attribute 'sleep'

Tags:

python

I'm receiving a strange error when running my program? I'm not sure why it wont let me sleep.

Traceback (most recent call last):
Not an add minute at all.
  File "C:/Users/admin/PycharmProjects/test/odd.py", line 15, in <module>
    time.sleep(0.05)
AttributeError: 'builtin_function_or_method' object has no attribute 'sleep'

Code:

from datetime import datetime
from time import time
from random import random

odds = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59]

right_this_minute = datetime.today().minute

for i in range(0, 11):
    if right_this_minute in odds:
        print("This minute seems a little odd.")
    else:
        print("Not an add minute at all.")

    time.sleep(random.randint(1, 60))
like image 414
Adam G Avatar asked Nov 29 '22 21:11

Adam G


2 Answers

Change from time import time to from time import sleep

Then you can use sleep directly instead of time.sleep

like image 120
Agile_Eagle Avatar answered May 13 '23 15:05

Agile_Eagle


snakecharmeb is right, and also, you need to import random rather than from random import random.

from datetime import datetime
import time
import random


odds = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59]

right_this_minute = datetime.today().minute

for i in range(0, 11):
    if right_this_minute in odds:
        print("This minute seems a little odd.")
    else:
        print("Not an add minute at all.")

    time.sleep(random.randint(1, 60))
like image 27
Marcus.Aurelianus Avatar answered May 13 '23 13:05

Marcus.Aurelianus