I am trying to make a class that is given a value, then executes a string in a list of strings based on the index given in order to change global variables. But I cannot figure out why the string that is executed cannot change the values of var1 and var0.
global var0, var1
class Change:
def __init__(self, executed):
self.executed = executed
def changeGlobals(self):
global var0, var1
exec(self.executed)
var0 = 0
var1 = 1
executed = 'var0 = var0+1; var1 = var1+1;'
var = Change(executed)
var.changeGlobals()
# is supposed to print 'var0 is 1, var1 is 2'
print('var0 is '+str( var0 )+', var1 is '+str( var1 ))
# actually prints 'var0 is 0, var1 is 1'