Calling private base methods

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Thu Apr 12 06:30:44 EDT 2007


En Thu, 12 Apr 2007 05:47:57 -0300, Jorgen Bodde  
<jorgen.maillist at gmail.com> escribió:

> Now that I am really diving into Python, I encounter a lot of things
> that us newbies find difficult to get right. I thought I understood
> how super() worked, but with 'private' members it does not seem to
> work. For example;

Someone already told you what happens here. But aren't *private* methods  
supposed to be private? That is, not called from outside the class.

> Is it possible to call a private base method? I come from a C++
> background, and I liked this construction as my base class has helper
> methods so that I do not have to  duplicate code.

It's been a while since I do any serious work in C++, but AFAIK you  
*can't* call a private method from another class (even from a derived one)  
unless you use "friend".
Maybe you want a "protected" method - by convention, in Python they're  
written as _name (single underscore).

-- 
Gabriel Genellina




More information about the Python-list mailing list