nonlocal fails ?

R.Wieser address at not.available
Thu Nov 14 08:06:47 EST 2019


Hello all,

I've just tried to use a "nonlocal MyVar" statement in a procedure 
defenition, but it throws an error saying "Syntax error: no binding for 
nonlocal 'MyVar' found.

According to platform.python_version() I'm running version 3.8.3

Why am I getting that error ? (already googeled ofcourse)

Testcode:
- - - - - - - - - - - -
Def Proc1()
    nonlocal MyVar
    MyVar = 5

MyVar = 7
Proc1()
print(MyVar)
- - - - - - - - - - - -
I've also tried moving "MyVar = 7" to the first line, but that doesn't 
change anything.  Using "global MyVar" works..

Regards,
Rudy Wieser





More information about the Python-list mailing list