static variables?

Chad Netzer cnetzer at mail.arc.nasa.gov
Tue Nov 19 23:48:30 EST 2002


On Tuesday 19 November 2002 18:59, Erik Max Francis wrote:

> As for the "why," I think it's just a historical accident which is too
> late to change now.

Actually, it isn't so random as that.  When you make a function with "def", 
it actually makes a function object right there, rather than making a promise 
to provide one later when linking.  If you redefine a function (not allowed 
in many languages), python will happily make a new function object using the 
same name, etc.

So, since the default argument is part of the definition, the default 
argument is actually created and bound, once, during the definition, not 
repeatedly during calling.  But if you call a function repeatedly, giving an 
empty list argument each time, for example, a list IS created each time.  It 
is all as you would expect, once you get into the proper mode of thinking 
about it.

-- 
Bay Area Python Interest Group - http://www.baypiggies.net/

Chad Netzer
cnetzer at mail.arc.nasa.gov




More information about the Python-list mailing list