unintentionaly shared attributes in two different instances

Emile van Sebille emile at fenx.com
Thu Dec 13 09:37:24 EST 2001


"maxm" <maxm at mxm.dk> wrote in message
news:lG2S7.7217$z4.958374 at news000.worldonline.dk...
> "Alexandre Fayolle" <alf at sagittarius.logilab.fr> wrote in message
>
> > Don't use mutable primitives (lists, dictionaries or class instances) as
> > default value in a method or function. See §4.7.1 in the Python
tutorial:
> >
> > "Important warning: The default value is evaluated only once. This makes
a
> > difference when the default is a mutable object such as a list or
> dictionary."
>
> Bummer ... thanks!
>
> regards Max M
>
>

The normal approach is:

def __init__(self, content=None):
    if content == None: content = []


--

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list