building embedded classes as in C/C++
Fred L. Drake, Jr.
fdrake at acm.org
Wed Aug 4 13:45:56 EDT 1999
Andy Beall writes:
> Here, 'p' does not seem to be class-wide while 'pos' and 'ang' are. Why
> the discrepancy?
Andy,
The 'p' set in the class statement is class-wide. Setting 'p' on an
instance creates a new instance-specific binding for 'p', which is
retrieved on subsequent attribute accesses since it overrides the
class-wide value. If you accessed it as Object.p, the original value
would still be available.
This is a situation where the "binding" and "namespaces" terminology
is pretty important and makes it easier to understand. There really
aren't variables in the C/C++/lots-of-others sense. Sections 9.1 and
9.2 in the tutorial may be worth reviewing here:
http://www.python.org/doc/current/tut/node11.html
-Fred
--
Fred L. Drake, Jr. <fdrake at acm.org>
Corporation for National Research Initiatives
More information about the Python-list
mailing list