Answer the question
In order to leave comments, you need to log in
How can I refer to a variable in another function in a function?
Python 3. PyQt4
Conditional question model:
There is a function "aa" with variables. I want to use these variables in the "bb" function like this:
def aa(self):
x = 3
y = 5
z = 6
def bb(self):
s = aa.x + 5
print('s = ',aa.x,'+ 5 = ',s)
bb()
def on_kat(self):
кат_index = self.listWidget_кат.currentRow() # принимает номер строки
уч_lst = basa.кат[кат_index+1]
self.listWidget_уч.clear()
self.listWidget_уч.addItems(уч_lst)
return кат_index
def on_kat_minus(self, кат_index):
кат_index = on_kat.кат_index
print('кат_index = ',кат_index)
Answer the question
In order to leave comments, you need to log in
In this form, no way.
Variables declared inside a function exist only for that function and only for the duration of its execution.
Accordingly, it is necessary either to move the declaration of variables outside the function - to some namespace common to both functions. Either return variables as the result of a function, and call that function to get its result.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question