Bug with [] as default value in functions? - bug.py (0/1)

Dinu Gherman dinu at reportlab.com
Thu Apr 12 07:49:23 EDT 2001


Hi,

I noticed a very strange behaviour: I've got a recursive function like
this:

  foo(spam, eggs=[]):
    ...
    return foo(spam, eggs=eggs

where the default argument for eggs, the empty list, is *empty* for
the top-level call only when it is explicitly provided with the func-
tion call like this:

  bar = foo(mySpam, eggs=[])

I've attached a more lengthy example showing, I hope, rather pre-
cisely what I mean.

Is this a bug or just a lack of understanding of recursion and name
spaces, delicate as they are, in my brain??

Regards,

Dinu


-- 
Dinu C. Gherman
dinu at reportlab dot com
http://www.reportlab.com
................................................................
"The only possible values [for quality] are 'excellent' and 'in-
sanely excellent', depending on whether lives are at stake or 
not. Otherwise you don't enjoy your work, you don't work well, 
and the project goes down the drain." 
                    (Kent Beck, "Extreme Programming Explained")



More information about the Python-list mailing list