static keyword

Nick Jacobson nicksjacobson at yahoo.com
Thu Apr 29 15:20:36 EDT 2004


>  >>> i = [10 ,11]
>  >>> firstcall = True
>  >>>
>  >>> def foo():
> ...     global i
> ...     global firstcall
> ...     if firstcall:
> ...             print "First pass"
> ...             firstcall = False
> ...     i[0] += 1
> ...     print i[0]
> ...
>  >>> foo()
> First pass
> 11
>  >>> foo()
> 12

Hmm.  I would like it, but it pollutes the global namespace.  Two
functions might want to use firstcall, for example (if they want to
just do something on the first pass).  That's an error at most, and
renaming issues at the least.

Thanks for the idea, though..



More information about the Python-list mailing list