On Wed, Aug 5, 2009 at 3:13 AM, TP<tribulati...@paralleles.invalid> wrote: > Hi everybody, > > See the following example: > > ######### > def tutu(): > > def toto(): >
nonlocal a #note: this requires a rather recent version of python > print a > a = 4 > print a > > a=2 > toto() > > tutu() > ########## > > I obtain the following error: > "UnboundLocalError: local variable 'a' referenced before assignment" > > This is because Python looks in the local context before looking in the > global context. > > The use of "global a" in toto() does not help because global allows to force > Python to look for the variable at the module level. > > So, how to share a variable between intricated functions? Details: http://www.python.org/dev/peps/pep-3104/ Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list