Defining a method final

Emile van Sebille emile at
Tue Jun 11 16:21:53 CEST 2002

"Eric Brunel" <eric.brunel at> wrote in message
news:ae4tvv$rvd$1 at
> Python now have an "official" means to make attributes private by
> them with a double-underscore. And it *does* prevent their use or
> overloading:

I don't know why I thought name mangling only happened at the module
level... But note that even here it's still usable, and that the user
has broken the rule of 'leading underscore == leave it alone'.

>>> class Test:
...     def __private(self): pass
>>> dir(Test)
['_Test__private', '__doc__', '__module__']
>>> dir(Test)
['_Test__private', '__doc__', '__module__']
>>> Test._Test__private
<unbound method Test.__private>


Emile van Sebille
emile at


More information about the Python-list mailing list