My first attempt at subclassing....Gahh!

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

"Robin Siebler" <robin.siebler at> wrote in message 
news:95c29a5e.0409131910.5c916122 at
> 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= []
>        for x in self.subdirs.keys():
>            output.append(self.subdirs[x].report())
>        return output
> class 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 method like this:

Hope this helps. 

More information about the Python-list mailing list