Override method name and original method access

Laszlo Nagy gandalf at shopzeus.com
Mon Nov 12 20:59:32 CET 2007

Donn Ingle wrote:
> In an unusual twist of code I have a subclass which overrides a method but
> it also needs to call the original method:
> class One:
>  def add (self, stuff):
>   self.stuff.append(stuff)
> class Two(One):
>  def __init__(self, otherstuff):
>   <MYSTERY>(otherstuff) #otherstuff must go into list within the parent.
>  #The override - totally different function in this context.
>  def add (self, data):
>   self.unrelated.append (data)
> For:
> I have tried:
>  self.One.add( otherstuff ) 
> No go.
>  super ( Two, self).add( otherstuff ) 
> Gives this error:TypeError: super() argument 1 must be type, not classobj
> (Which reminds me, how the heck does super work? I always get that error!)
This is a typical error. You get this when you try to use "super" with 
old style classes. You should try it with new style classes.

See: "class One(object):" instead of "class One:".

BTW you can always do a direct call:

def add(self,data):

and super isn't always the good thing to use.



More information about the Python-list mailing list