Why don't optional mutable objects show up in vars(func)?
Fredrik Lundh
fredrik at pythonware.com
Wed Sep 27 14:02:05 EDT 2006
Sean Hammond wrote:
>>>>> def func(x, y=[]):
>> ... y.append(x)
>> ... print y
>> ...
>>
>> y is initialized when the function is imported, not when the function
>> is executed.
>
> I thought it was initialised the first time the function gets called?
it's initialized (in the surrounding context) when the "def" statement
is executed.
</F>
More information about the Python-list
mailing list