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

libGdx unable to find files in android application data directory -

php - Webix Data Loading from Laravel Link -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -