13.14. Privacy
Attributes in Python are, by default, “public” all the time, accessible by both code within the module and modules that import the module containing the class.
Many OO languages provide some level of privacy for the data and provide only accessor functions to provide access to the values. This is known as implementation hiding and is a key component to the encapsulation of the object. Most OO languages provide “access specifiers” to restrict who has access to member functions.
Python 1.5 introduces an elementary form of privacy for class elements (attributes or methods). Attributes which begin with a double underscore (__) are mangled during run-time so direct access is thwarted. In actuality, the name is prepended with an underscore ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access