views:

62

answers:

1

I want to call a redefined private method from an abstract parent class. I am using django if that matters.

class Parent(models.Model):
    def method1(self):
         #do somthing
         self.__method2()

    def method2(self):
         pass # I also tried calling up a prent method with super

class child(Parent):
    def method1(self)
        super(Child, self).method1()

    def __method2(self):
        #do something

I get a

AttributeError: "'Chil' object has no attribute '_Parent__method2'"

What I am doing wrong ?

A: 

Initial double underscores prevent polymorphism since both the method definition and the method call get mangled, to two different names. Replace with a single underscore to fix this.

Also, double underscores are not used for "private" attributes, and you should discard whatever reference told you that they are. They're used for MI disambiguation.

Ignacio Vazquez-Abrams
Thanks. I'll have to re-read the use of simple and double undrscores. BTW, thanks for all your answers, you are a great help Ignacio. Much appreciated ;-)
PhilGo20