Name mangling
Fredrik Lundh
effbot at telia.com
Mon May 8 16:40:02 EDT 2000
ullrich at math.okstate.edu wrote:
> But usually when I don't get something it's because
> I haven't found the right page in the docs. Here that's
> not the case - I don't see how the bit in the docs about
> name mangling says that the code above should not work.
> ???
section 9.6 in the tutorial discusses this:
http://www.python.org/doc/current/tut/node11.html
"Any identifier of the form __spam (at least two
leading underscores, at most one trailing under-
score) is now textually replaced with
_classname__spam, where classname is the
current class name with leading underscore(s)
stripped. This mangling is done without regard
of the syntactic position of the identifier, so it
can be used to define class-private instance
and class variables, methods, as well as globals,
and even to store instance variables private to
this class on instances of other classes"
the language reference tells you that two leading under-
scores means class-private idenfifiers, but doesn't say
much more that that...
(send patches to python-docs at python.org!)
</F>
<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->
More information about the Python-list
mailing list