Calling a constructor in a default argument.

Miki Tebeka miki.tebeka at zoran.com
Mon Mar 8 14:52:04 CET 2004


Hello Bram,

> I wrote a function that takes a default argument.
> The default arg is set to a constructor call.
> 
> I expected this constructor to be called every time I call the func
> without the arg.
> 
> However, it turns out that the constructor is called only once.
> Is this the desired behaviour, or a known bug?
This is a strong runner for #1 question in comp.lang.python
http://www.python.org/doc/faq/general.html#why-are-default-values-shared-between-objects

HTH.
Miki



More information about the Python-list mailing list