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

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Apache Thrift Tutorial Error -