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

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).

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

Related

Visual Studio Code, Python, Alterations Not Running

I am trying to alter some code I have been given for my dissertation. However, any alterations to the modules (print statements, logging, and even trying to deliberately break the code with breaks) do not seem to affect the main program running as if those changes were not there, but changes to the main program does affect the output.
All the changes are saved and I have tried reimporting all the data files I am using and deleting all of the results before rerunning to try and start the program from "fresh". But no luck in fixing the issue.
Is there any fix to this problem? Apologies if it is an easy one, still starting out.
Main Program
eda = EDA()
cdr3_lengths = eda.get_length_of_repertoires(
repertoires=repertoires,
cdr3_col_name="aaSeqCDR3",
freq_col="cloneCount",
groups={
"01.TC8.14": "14days",
"02.TC4.14": "14days",
"03.SC8.14": "14days",
"04.SC4.14": "14days",
"05.TC8.21": "21days",
"06.TC4.21": "21days",
"07.SC8.21": "21days",
"08.SC4.21": "21days",
},
)
Module
class EDA:
# --init method etc --
def get_length_of_repertoires(
self,
repertoires: List,
groups: dict,
cdr3_col_name: str,
freq_col: str,
save_df: bool = False):
print("This isn't working")
cdr3_lengths = {}
self.logger.info("For loop fetching each repertorie.")
for repertoire in repertoires: #Repeat seqs len for count
self.logger.debug(repertoire)
.....
return 'value'
I have added some of the code that I am working with here, I believe it is being executed. I hope this helps a little more.

Use UINotificationFeedbackGenerator in pythonista Objc_util

I'm trying to use UINotifcationFeedbackGenerator in pythonista,
from objc_util import *
feedbackGenerator = ObjCClass('UINotifcationFeedbackGenerator')
feedbackGenerator = feedbackGenerator.alloc().init()
feedbackGenerator.notificationOccurred(0)
but running this causes the app to crash, with the error file saying
called more times than the feedback engine was activated
so searching it up, it seems the feedback Generator isn't tread safe, but using on_main_thread() didn't work either (or i'm just using it wrong). Through strangely enough, adding it to a method called by ui works here
Thanks for your help!
Maybe a little late ;-), but: You are overwriting feedbackGenerator which will cause the crash:
feedbackGenerator = feedbackGenerator.alloc().init()
Try this:
f = feedbackGenerator.alloc().init()
f.notificationOccurred(0)

Indentation Error in the Usage of 'def' in Python 3.7

def day_display_control(entered_variable,controlling_number,return_message):
if entered_variable == controlling_number:
return(return_message)
I have been trying to find a problem here, as IDLE keeps on giving an indentation error saying expected an indented block yet I have found none so far, my indentation width is 4 and I tried using only tab as well, haven't found the solution, thank you in advance as this is probably a really basic question.
P.S:
I have also tried to debug the rest of the code without this line, yet while this gives the same error:
def day_display():
day_display_number = day % 7
day_display = day_diplay_control(day_display_number,0,Monday)
day_display = day_diplay_control(day_display_number,1,Thuesday)
day_display = day_diplay_control(day_display_number,2,Wednesday)
day_display = day_diplay_control(day_display_number,3,Thursday)
day_display = day_diplay_control(day_display_number,4,Friday)
day_display = day_diplay_control(day_display_number,5,Saturday)
day_display = day_diplay_control(day_display_number,6,Sunday)
Do not mind the quality of the code, the problem is that previous 'def's don't cause this to happen, such as;
def typeWait(message,delay):
message = str(message)
print(message)
sleep(delay)
P.P.S: I have just realized, as of yesterday, that python was not 3.6 anymore, but instead 3.7 alpha 2, which leads me to believe that this is either a new feature or a bug, I have found no articles about either of them yet, so if anyone knows what the problem is, I would appriciate it a lot.
I agree with #jasonharper. Check if you mistyped = instead of ==, and also if any of these are missing: ), ] or }. It might not be near the block of these functions.

Python Subprocess.Popen attribute error?

am new to python. sorry if the below question is very basic.
i am getting attribute error in the below case. kindly advice want i missed.
am using python 2.4.
count = subprocess.Popen(["awk -F'n=' '{x+=$2}END{print x}' output"],stdout=subprocess.PIPE.communicate()[0],shell=True)
AttributeError: 'int' object has no attribute 'communicate'
thanks,
Rajesh
Replace
stdout=subprocess.PIPE.communicate()[0]
with
stdout=subprocess.PIPE
I guess this is what you wanted to type:
count = int(subprocess.Popen(["awk -F'n=' '{x+=$2}END{print x}' output"], stdout=subprocess.PIPE, shell=True).communicate()[0])
Please note that shell=True is insecure most of the time, and it's also unnecessarily slow. There is an easy way to avoid it in your case:
count = int(subprocess.Popen(('awk', '-Fn=', '{x+=$2}END{print x}', 'output'), stdout=subprocess.PIPE).communicate()[0])

Not allowing numbers in Glade with Python

I'm a fairly new Python programmer (started 3 days ago). I'm working as a apprentice for a civil engineer and he asked me to do some simpler tasks for his program, as of the objective I should work with is to not allow numbers from inputs in certain glade objects.
The code I've been struggling with creating is as such:
def testOmHeltal (self, number1):
textviewResultat = self.builder.get_object("textviewResultat")
text = gtk.TextBuffer()
try:
#print number1.get_text()
#temp = number1.get_text() + number1.get_text()
temp = float(number1.get_text())
except ValueError:
text.set_text("ERROR: Endast Nummer")
self.builder.get_object("hboxWarning").show()
self.builder.get_object("image12").show()
self.builder.get_object("textviewResultat").set_buffer(text)
return 0
self.builder.get_object("hboxWarning").hide()
self.builder.get_object("image12").hide()
def quit(self, widget):
sys.exit(0)
This code is called upon at the location of the glade object with this line:
self.testOmHeltal(entryGladeObject)
Now to the problem at hand, I allways get an Float error as such:
File "bvf.py", line 393, in utfora
+float(entryTjockleksskyddslager.get_text<>>>>
ValueError: invalid literal for float<>: 0.04e
0.04e is the invalid input and line 393 is a piece of my Chiefs code, since all he uses is float all the time and I shouldn't meddle with it too much I'm kind of panicking alittle..
I understand that float can only start and end with a number to not give an error, but since my "code" bit wants an error(or rather, an exception) to start the 'hboxWarning' and 'image12' of someone using a letter instead of the supposed number, I'm at a loss at what to do ><
Instead of showing my error with hboxWarning and image12, nothing happens at all...
Any hints or advice would help alot.
I don't know if I understood correctly, but the error is not on your code, right?
All I can assume is that there's a piece of code trying to convert the value to float before your verification. If that's the case, you should verify the value before any processing is done on it, or move the try-except code around the faulty code, depending on the processing itself (for example, if the processing implies database manipulation, it would be safer to do all the verifications previously).
If the error is happening before the line where you run self.testOmHeltal(entryGladeObject), the execution of the signal/method stops right away and your code is never excecuted; that's why the warning isn't showing.

Categories

Resources