I am sure that they asked and answered about this, but I could not find it specifically:
I just pick Python and I don't understand the problem with variable variable .
I simplified the problem as follows:
Case 1:
def lev1():
exec("aaa=123")
print("lev1:",aaa)
lev1()
Case 2:
def lev1():
global aaa
exec("aaa=123")
print("lev1:",aaa)
lev1()
Case 3:
def lev1():
exec("global aaa ; aaa=123")
print("lev1:",aaa)
lev1()
Case 1and Case 2have aaaundefined in the print instruction.Case 3works. Where aaadoes it really exist in Case 1and Case 2?- Is there a way to access
aaacase 1 without an announcement global?
source
share