Confusion regarding constructor as default value

aine_canby at yahoo.com aine_canby at yahoo.com
Thu Sep 27 09:44:51 EDT 2007


On 27 Sep, 15:34, "Diez B. Roggisch" <de... at nospam.web.de> wrote:
>  aine_ca... at yahoo.com wrote:
> > Why are the following different?
>
> > def AddRow(self, rowName, tableRow=TableRow(ReleaseDate(""),
> > ExpiryDate(""))):
> > # check to see if the row already exists, if not add it to the
> > container
>
> > if not self.dict.has_key(rowName):
> > self.dict[rowName] = tableRow
>
> > def AddRow(self, rowName, tableRow):
> > # check to see if the row already exists, if not add it to the
> > container
>
> > if not self.dict.has_key(rowName):
> > self.dict[rowName] = TableRow(ReleaseDate(""), ExpiryDate(""))
>
> > It seems that when I use the first function that I'm getting duplicate
> > objects in self.dict
>
> > Thanks for your help,
>
> It's a FAQ.
>
> http://effbot.org/pyfaq/why-are-default-values-shared-between-objects...
>
> Diez- Dölj citerad text -
>
> - Visa citerad text -

Cool, I understand now. It was my understanding of how Python works
that was at fault.




More information about the Python-list mailing list