nonlocal fails ?

R.Wieser address at not.available
Thu Nov 14 12:57:24 EST 2019


Michael,

> 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.

Oh blimy!   You're right.    Its an at compile-time thing, not a runtime 
one.

Thanks for the heads-up.

> I know of no sane way that a function could work with the scope of
> any arbitrary caller.

The trick seems to be to emulate a "by reference" call, by using a mutable 
object as the argument and stuff the value inside of it (IIRC a tuple with a 
single element).

> What would happen if the caller's scope didn't have any
> names that the function was looking for?

Handle it the same as any other mistake, and throw an error ?

Regards,
Rudy Wieser




More information about the Python-list mailing list