Privacy and Inheritance

Erik Max Francis max at alcyone.com
Thu Sep 5 15:01:18 EDT 2002


Eric Brunel wrote:

> I just meant that Python has no way of enforcing "protectedness", as
> leading double underscores (kind of) enforce privateness. As you say,
> using
> a single leading underscore in protected attribute names is merely a
> convention, even if it's a strong one: Python won't prevent any use of
> the
> attribute, neither from sub-classes, nor from the "outside world".
> Anybody
> not knowing the convention can use these attributes in any way without
> any
> problem.

That's right.  Python takes the approach that "We're all adults here,"
and presumes that people will behave.  In many languages the concept of
restricted access can be circumvented in varying ways with increasing
levels of ugliness, so you can think of restricted access as really a
hint (albeit a very strong one in those languages where it is very
awkward).

Python just leaves these things at the hint level (with the exception of
double underscore name mangling, which is a fairly recent addition).

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ There is nothing so subject to the inconstancy of fortune as war.
\__/ Miguel de Cervantes
    Church / http://www.alcyone.com/pyos/church/
 A lambda calculus explorer in Python.



More information about the Python-list mailing list