My first attempt at subclassing....Gahh!

Dan Perl dperl at rogers.com
Tue Sep 14 07:19:56 CEST 2004


"Robin Siebler" <robin.siebler at palmsource.com> wrote in message 
news:95c29a5e.0409131910.5c916122 at posting.google.com...
> I'm using Python 2.2.3 and the error I get is 'TypeError: cannot
> create 'instance method' instances'.
>
> import filecmp
>
> class dircmp(filecmp.dircmp):
>    def my_report_partial_closure(self):
>        output= []
>        self.report()
>        for x in self.subdirs.keys():
>            output.append(self.subdirs[x].report())
>        return output
>
> class report(filecmp.dircmp.report):

filecmp.dircmp.report is a method in the filecmp.dircmp class.  You have to 
subclass from another class and you cannot subclass from a method.  What you 
probably want is define a subclass of filecmp.dircmp (like your own dircmp) 
and define a method report(self) inside it.  This means that you are 
overriding the superclass's report( ) method.  Inside your report( ) method, 
you can still use the filecmp.dircmp.report method like this: 
filecmp.dircmp.report(self).

Hope this helps. 





More information about the Python-list mailing list