jacek.generowicz at cern.ch
Thu Mar 11 10:15:54 CET 2004
Subhash Chandra <nospam_yschandra at yahoo.com> writes:
> How can I make counter variable in function foo reference to global
> counter variable in the following code.
add the line " global counter" just after "def foo():"
> Generally C programmers tend to write code like that I am looking
> for simple way to do it in python.
Generally C programmers do horrible things. Please consider whether
you really, really should be emulating C style in Python.
> --- BEGIN ---
> counter = 0
> def foo():
> if counter < 10:
> print "count = ", counter
> counter += 1
> --- END ---
More information about the Python-list