static keyword
Nick Jacobson
nicksjacobson at yahoo.com
Fri Apr 30 02:06:02 EDT 2004
Peter Hansen <peter at engcorp.com> wrote in message news:<WeKdnUQ3hq4BKwzdRVn-hg at powergate.ca>...
> Nick Jacobson wrote:
>
> > Yes, that is excellent. Thank you very much. :)
> >
> > The good news: you can reset all your "static" data whenever you want,
> > by calling foo(). Can't do that in C.
> >
> > The bad news: I just hope I don't forget and call foo() instead of
> > g.next().
> > I would rather the command foo() by default call the next iteration,
> > and, say, foo().reset() would recall the function from scratch. But
> > that's neither here nor there..
>
> Do this then (and this is, if not a hack, at least unusual style):
>
> >>>def foo_reset():
> # same as previous foo was, just renamed
>
> >>>foo = foo_reset().next
> >>>foo()
> First pass
> 11
> >>>foo()
> 12
>
> Happy now? ;-)
>
> -Peter
Yes, in fact that's very clever. Thanks! :)
More information about the Python-list
mailing list