Maintaining a list
Terry Reedy
tjreedy at udel.edu
Wed Feb 18 09:37:17 EST 2004
"Steve" <dippyd at yahoo.com.au> wrote in message
news:403311F6.2070202 at yahoo.com.au...
> How about using a global variable? Define a variable in
> your main program:
>
> mylist = []
>
> def myroutine(x)
> global mylist
Stylistic note:
Since the global name mylist is not rebound, this declaration is not
needed.
Since the global name mylist must not be rebound to meet its purpose,
I think the declaration positively should not be present, so it cannot be
rebound,
even by accident. Documenting the read-only use of a global with a comment
(especially in a much longer function) is a different matter, as with
# global mylist
> mylist.append(x)
This mutates the object bound to 'mylist' without changing the binding.
> print mylist
> return None
Terry J. Reedy
More information about the Python-list
mailing list