Defining a method final
Emile van Sebille
emile at fenx.com
Tue Jun 11 10:21:53 EDT 2002
"Eric Brunel" <eric.brunel at pragmadev.com> wrote in message
news:ae4tvv$rvd$1 at wanadoo.fr...
> Python now have an "official" means to make attributes private by
prefixing
> 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 fenx.com
---------
More information about the Python-list
mailing list