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.

classification
Title: tutorial section 9.3.3 documentation problem
Type: Stage:
Components: Documentation Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, eli.bendersky, ori.livneh
Priority: normal Keywords: easy

Created on 2011-11-06 03:21 by eli.bendersky, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg147137 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2011-11-06 03:21
User report on the docs@ list:

-----

http://docs.python.org/tutorial/classes.html#instance-objects

I think the "counter" attribute is mentioned for the first time in the
example code, not "in Instance of MyClass created above", i.e. class
MyClass does not contain "counter" attribute.

"x.counter = 1
while x.counter < 10:
   x.counter = x.counter * 2
print x.counter
del x.counter"

Best Regards,
Jussi Peltonen
msg147139 - (view) Author: Ori Livneh (ori.livneh) * Date: 2011-11-06 04:01
That's exactly the point: in Python, data attributes don't need to be declared in the class definition.
msg147140 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2011-11-06 04:06
Yep, I agree, Ori.

The paragraph immediately preceding the code sample says:

    "Data attributes need not be declared; like local variables, they spring into existence when they are first assigned to [...] the following piece of code will print the value 16, without leaving a trace"

Which is what the code sample demonstrates.
History
Date User Action Args
2022-04-11 14:57:23adminsetgithub: 57561
2011-11-06 04:07:24eli.benderskysetstatus: open -> closed
resolution: not a bug
2011-11-06 04:06:45eli.benderskysetmessages: + msg147140
2011-11-06 04:01:34ori.livnehsetnosy: + ori.livneh
messages: + msg147139
2011-11-06 03:21:37eli.benderskycreate