Newbie: anything resembling static?
Terry Reedy
tjreedy at udel.edu
Sat Feb 1 17:37:36 EST 2003
"Tom" <nonotreally999 at yahoo.com> wrote in message
news:f1d59fef.0302011305.34a2836a at posting.google.com...
> Alex Martelli <aleax at aleax.it> wrote in message
news:<96YZ9.102138$0v.2963371 at news1.tin.it>...
> > def five():
> > staticvar = []
> > def innerfive():
> > staticvar.append('x')
> > return ''.join(staticvar)
> > return innerfive
> > five = five()
>
> I've played around with the several options in Alex's msg and
learned
> some things I didn't know about nested scopes. (Thanks, Alex.) I
> also read PEP 227 (and understood many parts of it), but I still
have
> one question: after I've called the function 'five' several times,
is
> there a way to see the current value of 'staticvar' in an
interactive
> session?
To do this (without making innerfive global), you should rewrite above
as class with __call__, as I believe I posted before.
TJR
More information about the Python-list
mailing list