Extending base class methods

Sizer sizer at nospam.com
Tue Apr 19 16:42:03 EDT 2005


henrikpierrou at hotmail.com wrote in
news:1113919270.802463.54310 at l41g2000cwc.googlegroups.com: 
> 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 added these lines to your code:

foo = MSD()
foo.printer()

And it worked perfectly (python 2.3.3). You would get that error if you 
accidentally did something like:

foo = MSD()
MSD.printer()   # oops, should be foo.printer()




More information about the Python-list mailing list