Puzzling: local variable in recursive function made global?

Diez B. Roggisch deets at nospam.web.de
Thu Mar 26 12:50:20 EDT 2009


Daniel Oberski schrieb:
> Hello all,
> 
> 
> I wrote this function to recurse through a tree structure of Nodes 
> connected by Branches. 
> 
> I use a local variable seen_nodes to mark off Nodes already seen by the 
> function (i.e. add them to a list).

That's not a local variable, that is a default argument. Which is in 
fact only created once for each function, yes.

http://effbot.org/pyfaq/why-are-default-values-shared-between-objects.htm

Diez



More information about the Python-list mailing list