22 October 2010

Python private functions

If the name of a Python function, class method, or attribute starts with (but doesn't end with) two underscores, it's private; everything else is public. Python has no concept of protected class methods; class methods are either private or public.

The privateness are implemented through a special renaming tricks done by python interpreter/compiler:

Variable __var in class cls gets replaced by _cls__var by compiler!

No comments: