Will python never intend to support private, protected and public?
Fredrik Lundh
fredrik at pythonware.com
Wed Sep 28 11:45:37 EDT 2005
Tony Meyer wrote:
>> I thought about it, but I didn't mention it in the end because this
>> feature ("name mangling") isn't intended as a mechanism for making
>> things private - it's intended to prevent namespace clashes when doing
>> multiple inheritance.
>
> That's not what the documentation says:
>
> """
> 9.6 Private Variables
>
> There is limited support for class-private identifiers.
> [...]
> Name mangling is intended to give classes an easy way to define
> ``private'' instance variables and methods,
> [...]
> """
>
> <http://docs.python.org/tut/node11.html>
the sentence you're quoting the first part of continues:
without having to worry about instance variables defined by derived
classes
and the paragraph later says:
Note that the mangling rules are designed mostly to avoid accidents
and both sentences are from the *tutorial*, which doesn't exactly
qualify as a design document. if you want more rationale, here's the
post that led to the current design:
http://groups.google.com/group/comp.lang.python/msg/e79f875059d9a2ba
"In my version, private data has it's own scope, so that name clashes
will not occur if a private with the same name is used in a subclass."
see the rest of that thread for more about the history of __.
</F>
More information about the Python-list
mailing list