default value in __init__

Chris Rebert clp at rebertia.com
Thu Oct 9 10:43:45 CEST 2008


On Thu, Oct 9, 2008 at 1:39 AM, kenneth <kenneth at inwind.it> wrote:
> On Oct 9, 10:14 am, Christian Heimes <li... at cheimes.de> wrote:
>> kenneth wrote:
>> > the 'd' variable already contains the 'self.d' value of the first
>> > instance and not the default argument {}.
>>
>> > Am I doing some stupid error, or this is a problem ?
>>
>> No, it always contains the default argument because default values are
>> created just ONE TIME.http://effbot.org/pyfaq/why-are-default-values-shared-between-objects...
>
>
> Wow, it's a very "dangerous" behavior ...
>
> Just to know, is this written somewhere in the python documentation or
> one has to discover it when his programs fails to work ;-) ?

It's mentioned in the tutorial (note the "Important warning"):
http://docs.python.org/tutorial/controlflow.html#default-argument-values

Cheers,
Chris
-- 
Follow the path of the Iguana...
http://rebertia.com

>
> Paolo
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list