H
henrikpierrou
Hi,
I am trying to extend an overridden base class method (printer) by
printing some extra fields and then calling the base class method.
Extract from the python tutorial:
'An overriding method in a derived class may in fact want to extend
rather than simply replace the base class method of the same name.
There is a simple way to call the base class method directly: just call
"BaseClassName.methodname(self, arguments)". '
Any ideas why this does not work? I get the error "TypeError: unbound
method printer() must be called with Field_Collection instance as first
argument (got MSD instance instead)"):
#=====================================================================================
class Field_Collection:
fieldList = []
def add(self, name, size, compression, responseValue, value,
description):
self.fieldList.append( Field(name, size, compression,
responseValue, value, description) )
def update(self):
print "updating field"
def get(self):
print "getting field"
def printer(self):
for x in self.fieldList:
x.printer()
#=====================================================================================
class MSD(Field_Collection):
standard = ""
decField = ""
def printer(self):
print "Standard: " + self.standard
print "decField: " + self.decField
Field_Collection.printer(self)
#=====================================================================================
w2k, python 2.3
I am trying to extend an overridden base class method (printer) by
printing some extra fields and then calling the base class method.
Extract from the python tutorial:
'An overriding method in a derived class may in fact want to extend
rather than simply replace the base class method of the same name.
There is a simple way to call the base class method directly: just call
"BaseClassName.methodname(self, arguments)". '
Any ideas why this does not work? I get the error "TypeError: unbound
method printer() must be called with Field_Collection instance as first
argument (got MSD instance instead)"):
#=====================================================================================
class Field_Collection:
fieldList = []
def add(self, name, size, compression, responseValue, value,
description):
self.fieldList.append( Field(name, size, compression,
responseValue, value, description) )
def update(self):
print "updating field"
def get(self):
print "getting field"
def printer(self):
for x in self.fieldList:
x.printer()
#=====================================================================================
class MSD(Field_Collection):
standard = ""
decField = ""
def printer(self):
print "Standard: " + self.standard
print "decField: " + self.decField
Field_Collection.printer(self)
#=====================================================================================
w2k, python 2.3