This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vladc6
Recipients vladc6
Date 2009-11-02.21:55:34
SpamBayes Score 2.8984294e-07
Marked as misclassified No
Message-id <1257198936.49.0.96904959127.issue7254@psf.upfronthosting.co.za>
In-reply-to
Content
If a class member is declared outside of a function, it's creation is
_not_ repeated with every new instance of the class. Instead, the same
member is created during the first instance and then shared by all the
subsequent instances of that class. This is wrong, because a new member
should be created for every instance.

I have attached a sample code contrasting the incorrect behavior (on
top) with the correct behavior (on bottom). Python behaves correctly if
the member is declared in __init__ (that is, Python initializes a new
member for every instance).

The output of "print b.greet" and "print d.greet" should be the same and
should read "['Howdy']".
History
Date User Action Args
2009-11-02 21:55:36vladc6setrecipients: + vladc6
2009-11-02 21:55:36vladc6setmessageid: <1257198936.49.0.96904959127.issue7254@psf.upfronthosting.co.za>
2009-11-02 21:55:35vladc6linkissue7254 messages
2009-11-02 21:55:34vladc6create