Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: 'int' object has no attribute 'sleep'

I am fairly new to Python (and programming in general), so please excuse my lack of knowledge or understanding to something you may find obvious. I'm not stupid though, so hopefully I should be able to work it out.

I am making a small text-based survival game, and I have encountered an issue which I cannot seem to solve, which is the:

AttributeError: 'int' object has no attribute 'sleep'

In the console when I try and run my program.

import time , sys , random , shelve
# /gather command
if '/gather' in Input and command_state == True:
    if 'wood' in Input:
        print('Collecting wood...')
        if tool != "Axe": 
            time.sleep(random.randrange(5 , 10))
            print("Test")
        else:
            time.sleep(random.randrange(5 , 10))
            print("Test")

I really don't understand what is causing this and after looking through the advice given on similar topics I have found no solution. Any help would be appreciated!

If you'd like me to put up the whole script, please just ask. I have only put up the block of code that was causing the issue (because none of the other code seemed to affect anything here).

like image 233
BFI01 Avatar asked Dec 25 '22 02:12

BFI01


1 Answers

As commented above you are overwriting the time module by making a variable named time. Simply rename the time variable!

like image 182
zerotwo77 Avatar answered Jan 09 '23 11:01

zerotwo77