How to use variable from previous scope in Python -


i have following code:

def test():     def printa():         def somethingelse():             pass         print(a)         aha = a[2]       = [1, 2, 3]     while true:         printa()  test() 

i've noticed code work fine, if change aha a, says a not defined.

is there way set a value within printa?

in python 3, can set variable nonlocal

def test():     = [1, 2, 3]     def printa():         nonlocal         def somethingelse():             pass         print(a)         = a[2]      while true:         printa()  test() 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -