in reply to Re^3: Nesting Functions
in thread Nesting Functions

> The mess starts because you can't use something like strict* to catch typos and Py3 needed to introduce nonlocal to mark assignments which are not declarations.

Another disturbing thing is that Python does hoisting like JS.

if it encounters a (implicit) declaration of a var somewhere at the end of a function, it will bind all var to the same private storage.

see demo of the mess in fun2()

>>> a=666 # global >>> def fun1(): ... print a # global ... >>> def fun2(): ... print a # privat ... a = 33 # declaration ... >>> fun1() 666 >>> fun2() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 2, in fun2 UnboundLocalError: local variable 'a' referenced before assignment >>>

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice