I'm doing the following in the python interpreter and it works:
rhce=rhcsa=0
args=['rhce','rhcsa']
for cert in args:
exec(cert+'+=1')
print(eval(cert))
>>> 1
>>> 1
As you can see the variable is incremented, whether you use print(rhce) or print(eval(cert)). However, when I put the exact same snippet of code inside a class function, it no longer works. No exceptions are thrown, but the variable never increments. It's like the exec is not working:
def addCertUser(self,userid,args):
rhcsa=rhce=0
print(args)
try:
for cert in args:
exec(cert+'+=1')
print(eval(cert))
except Exception as e:
print(e)
>>> ['rhce', 'rhcsa']
>>> 0
>>> 0
What am i missing here?