Defining a method final
Jerzy Karczmarczuk
karczma at info.unicaen.fr
Tue Jun 11 09:42:30 EDT 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
> overloading:
>
> class A:
> def __private(self): pass
> class B(A):
> pass
> o = B()
> o.__private()
>
> 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
o=A()
o.__private()
won't work. But launch dir(A) and look.)
Jerzy Karczmarczuk
More information about the Python-list
mailing list