faqts : Computers : Programming : Languages : Python : Common Problems

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

4 of 6 people (67%) answered Yes
Recently 3 of 5 people (60%) answered Yes

Entry

Can I implement access control in my classes (equivalent to C++'s private, public, protected, etc...)?

Sep 2nd, 2000 02:29
unknown unknown, Alex Martelli


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").