[docs] [issue11318] Python 3.2 FAQ example code typo?

R. David Murray report at bugs.python.org
Fri Feb 25 14:23:29 CET 2011


R. David Murray <rdmurray at bitdance.com> added the comment:

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.

----------
nosy: +r.david.murray
type:  -> behavior

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11318>
_______________________________________


More information about the docs mailing list