Message94851
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']". |
|
Date |
User |
Action |
Args |
2009-11-02 21:55:36 | vladc6 | set | recipients:
+ vladc6 |
2009-11-02 21:55:36 | vladc6 | set | messageid: <1257198936.49.0.96904959127.issue7254@psf.upfronthosting.co.za> |
2009-11-02 21:55:35 | vladc6 | link | issue7254 messages |
2009-11-02 21:55:34 | vladc6 | create | |
|