Message136146
| Author |
ezio.melotti |
| Recipients |
docs@python, ezio.melotti, georg.brandl, lukasz.langa, rhettinger, sheep, tim.golden |
| Date |
2011年05月17日.10:33:45 |
| SpamBayes Score |
2.5526864e-05 |
| Marked as misclassified |
No |
| Message-id |
<1305628426.66.0.0687617512452.issue12086@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
FWIW that section used to be called "Private variables through name mangling" back in 1.5, and started by saying "There is now limited support for class-private identifiers.".
PEP8 [0] also talks about the name mangling in several places, and carefully avoids the use of "private":
"""
To avoid name clashes with subclasses, use two leading underscores to
invoke Python's name mangling rules.
Python mangles these names with the class name: if class Foo has an
attribute named __a, it cannot be accessed by Foo.__a. (An insistent
user could still gain access by calling Foo._Foo__a.) Generally, double
leading underscores should be used only to avoid name conflicts with
attributes in classes designed to be subclassed.
"""
And it even includes the following two notes:
"""
We don't use the term "private" here, since no attribute is really
private in Python (without a generally unnecessary amount of work).
"""
"""
Not everyone likes name mangling. Try to balance the
need to avoid accidental name clashes with potential use by
advanced callers.
"""
[0]: http://www.python.org/dev/peps/pep-0008/ |
|