Strange Behavior

Carsten Haese carsten at uniqsys.com
Mon Oct 16 13:10:42 EDT 2006


On Mon, 2006-10-16 at 10:51, Steven D'Aprano wrote:
> On Mon, 16 Oct 2006 07:26:05 -0700, abcd wrote:
> 
> > class Foo:
> >     def __init__(self, name, data=[]):
> 
> The binding of the name "data" to the empty list happens at compile time,
> not runtime.

I think this statement needs to be clarified. The binding of "data" to
the empty list *does* happen at runtime, not at compile time. However,
the binding happens only once, when the "def" statement is executed, as
opposed to every time the __init__ function is called.

-Carsten





More information about the Python-list mailing list