Defining a method final
karczma at info.unicaen.fr
Tue Jun 11 15:42:30 CEST 2002
Eric Brunel wrote:
> Python now have an "official" means to make attributes private by prefixing
> them with a double-underscore. And it *does* prevent their use or
> class A:
> def __private(self): pass
> class B(A):
> o = B()
> results in:
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> AttributeError: B instance has no attribute '__private'
Some newbies may understand this wrongly. The attribute is still
accessible, it has just a different name: _A__private etc.
(You don't even need the class B to find out that
won't work. But launch dir(A) and look.)
More information about the Python-list