Access control in classes

Alex Martelli aleaxit at yahoo.com
Fri Sep 1 00:39:01 CEST 2000


"Fernando Rodriguez" <frr at mindless.com> wrote in message
news:HZxr5.291$zc4.10591 at m2newsread.uni2.es...
> Hi!
>
> How can I implement some access control in my classes (equivalent to C++'s
> private, public, protected, etc...)? O:-)

Naming an item with two leading underscores (and without two
_trailing_ underscores as well) is as close to "private" as Python
comes (the compiler decorates the attribute name with the
classname, so no accidental clash is possible any more).  There
is, AFAIK, no parallel to "protected" (nor any particular need for
it; it is, after all, a feature which Stroustrup deeply regrets
having let himself be talked intro introducing in C++ -- see his
excellent book "Design & Evolution of the C++ Programming
Language").


Alex






More information about the Python-list mailing list