where dos the default agument live in? local name spaces or gloabal namespaces or else?

Aahz aahz at pythoncraft.com
Fri Aug 16 05:40:17 CEST 2002


In article <e895ad50.0208151917.61e959c2 at posting.google.com>,
lion <dance_code at hotmail.com> wrote:
>
>I just feel name spaces are ambiguous in a sense.If I defined a
>function in the Python shell:
>>>>def f(a, L=[]):
>       L.append(a)
>       return L
>and I invoked it with the default agrument value: f(1).Now I don't
>know where the default agument L lives in? No matter I use dir() or
>dir(f),there is no L listed in the result.

There's two separate issues here.  First of all, L is part of the
function local namespace.  I'm not certain, but I believe that L's
default lives in f's code object; L gets set to the default value as
part of the frame setup process.

Namespaces are not ambiguous, but they *are* complex and a bit
complicated, too.

Side note: you probably don't want a mutable as a function default.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

Project Vote Smart: http://www.vote-smart.org/



More information about the Python-list mailing list