I have some code that's structured like so.
def function():
test = myClass()
var = 1
running = True
while running:
if var == 1:
print(1)
test.update(var)
if var == 2:
print(2)
class myClass:
def update(self, var):
var = 2
Essentially the code should print '1' only once and then print an indefinite number of '2's as the value of var is changed from '1' to '2' in the update method. However, it just prints loads of '1's.
How do you change the value of a variable found in a function by using a class's method in that function?
I've also tried with global variables and it doesn't work (and I've heard is generally frowned upon).