variable refences for nested functions

thephoenix235 at gmx.net thephoenix235 at gmx.net
Mon Oct 21 00:57:37 EDT 2002


A class would be too heavy duty. You're idea works great. I'm doing this
now.

class Blank: pass


def foo ():
   top = Blank ()
   top.a = 1

   def bar():
      print top.a
      top.a=2  

   bar()
   print top.a

foo()


Thanks.


> 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

-- 
+++ GMX - Mail, Messaging & more  http://www.gmx.net +++
NEU: Mit GMX ins Internet. Rund um die Uhr für 1 ct/ Min. surfen!





More information about the Python-list mailing list