Message129362
Read a little further:
Caution: within a method of C, an assignment like ``self.count = 42`` creates a new and unrelated instance named "count" in ``self``'s own dict.
That is, c.count refers to C.count right up until the point where c.count is assigned a value. So, c.count = c.count + 1 will add one to the current value of C.count, and assign it to the *instance* variable c.count. c.count at that point no longer refers to the *class* variable C.count. Thus your change to the __init__ function would completely defeat the purpose of the example (which is to show how to use a *class* variable.
If you can suggest a concise wording that would have made this clearer to you, we can consider a doc patch. |
|
Date |
User |
Action |
Args |
2011-02-25 13:23:29 | r.david.murray | set | recipients:
+ r.david.murray, Retro, docs@python |
2011-02-25 13:23:28 | r.david.murray | set | messageid: <1298640208.93.0.850735850736.issue11318@psf.upfronthosting.co.za> |
2011-02-25 13:23:28 | r.david.murray | link | issue11318 messages |
2011-02-25 13:23:28 | r.david.murray | create | |
|