Message308537
Hello,
"PEP 3104 -- Access to Names in Outer Scopes" introduced the keywords "global" and "nonlocal". but didn't make clear (to me) if this behaviour is a bug, an intentional feature, or a design hole which might be considered good or bad.
I have observed that when the nonlocal keyword gives acces to a grand parent function's variable, the presence in the parent function, of an access to a global variable with the same name, blocks it with a syntax error (SyntaxError: no binding for nonlocal 'a' found).
a = "a : global"
def f():
a = "a : local to f"
def g():
# global a # uncommenting this line causes a syntax error.
# a = a+", modified in g"
def h():
nonlocal a
a = a+", modified in h"
h()
print (f"in g : a = '{a}'")
g()
print (f"in f : a = '{a}'")
f()
print (f"glogal : a = '{a}'") |
|
Date |
User |
Action |
Args |
2017-12-18 09:59:49 | Camion | set | recipients:
+ Camion |
2017-12-18 09:59:49 | Camion | set | messageid: <1513591189.6.0.213398074469.issue32361@psf.upfronthosting.co.za> |
2017-12-18 09:59:49 | Camion | link | issue32361 messages |
2017-12-18 09:59:49 | Camion | create | |
|