static keyword
Peter Hansen
peter at engcorp.com
Thu Apr 29 22:14:50 EDT 2004
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
More information about the Python-list
mailing list