Private functions and inheritance

Bjoern Schliessmann usenet-mail-0306.20.chr0n0ss at spamgourmet.com
Mon Jul 16 16:54:18 CEST 2007


Maciej Blizi?ski wrote:

> calling B::call_bar(): B::bar()
> calling B::call___bar(): A::__bar()

(BTW, there is no :: operator in Python. It should be, e. g., 
B.bar().)

> In the latter case, it calls the base class' implementation. It
> probably goes along with Python's spec, but I found it surprising.

__-prepended names are dynamically mangled to include the class
name. Hence, B.__bar doesn't overwrite A.__bar in B.

> I don't want to expose the __bar() function outside,

In principle, you do. Always. Public or Private is just convention
in Python. Even __-prepended names can be accessed from outside.

Couldn't find it in the docs though. Quite inconcise.

Regards,


Björn

-- 
BOFH excuse #120:

we just switched to FDDI.




More information about the Python-list mailing list