nonlocal fails ?

Richard Damon Richard at Damon-Family.org
Thu Nov 14 23:36:58 EST 2019


On 11/14/19 12:57 PM, R.Wieser wrote:
> 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).

tuples are immutable, use a list or a dictionary.

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

-- 
Richard Damon



More information about the Python-list mailing list