nonlocal fails ?

Michael Torrie torriem at gmail.com
Thu Nov 14 10:54:28 EST 2019


On 11/14/19 7:15 AM, R.Wieser wrote:

> Too bad though, it means that procedures that want to share/use its callers 
> variables using nonlocal can never be called from main.  And that a caller 
> of a procedure using nonlocal cannot have the variable declared as global 
> (just tested it).

nonlocal does not share or use its *caller's* variables.  Rather it
reaches into the scope of the outer function where it was defined.
That's a very different concept than what you're proposing.

I know of no sane way that a function could work with the scope of any
arbitrary caller.  Remember that even inner functions can be returned
and called from anywhere, even other functions or modules.  What would
happen if the caller's scope didn't have any names that the function was
looking for?

What are you trying to accomplish?


More information about the Python-list mailing list