variable refences for nested functions
Terry Reedy
tjreedy at udel.edu
Mon Oct 21 00:47:29 EDT 2002
<thephoenix235 at gmx.net> wrote in message
news:mailman.1035169107.10575.python-list at python.org...
> Hi,
>
> As I understand it, a nested function can access the local variables
of the
> enclosing function.
As you discovered, it can read but not write.
> anyone have a better workaround?
You have the right idea: make enclosing function var mutable. Besides
'class'ing it (a bit too heavy duty for most purposes, you can also
wrap it as a list. For multiple vars, use a list of appropriate
length. Or use a dict for name instead of positional access.
Terry J. Reedy
More information about the Python-list
mailing list