A change to a class attribute does not propagate - bug or feature?

Greg Goodman chironsw at swbell.net
Fri Jan 11 10:08:40 EST 2002


The default value of the Name parameter gets evaluated exactly once, the
first time the newClass.__init__() code is executed.  Ever afterward,
the default Name is what it is, regardless of subsequent changes to
baseClass.ClassId.

> class newClass(baseClass):
>     def __init__(self, Name = "newClass" + str(baseClass.ClassId)):
>         baseClass.__init__(self, Name)class newClass(baseClass):

If you want the default defaut newClass Name to be dependent on the
_current_ baseClass.ClassId, try this:

class newClass(baseClass):
    def __init__(self, Name = None):
        if not Name:
            Name = "newClass" + str(baseClass.ClassId)
        baseClass.__init__(self, Name)

Hope this helps,

Greg



More information about the Python-list mailing list