My first attempt at subclassing....Gahh!
Robin Siebler
robin.siebler at palmsource.com
Mon Sep 13 23:10:13 EDT 2004
I want to use filecmp.dircmp, but it only prints to the screen, there
is no way to capture the output. So I thought that I should simply be
able to subclass it to return a list (Danger! Danger, Will! Simple
and Subclass should never be used in the same sentence!). However, my
first attempt (pathetic as it may be), results in an error that I
don't understand. Obviously, I'm doing something wrong, but what?
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):
def my_report(self): # Print a report on the differences
between a and b
# Output format is purposely lousy
output = []
output.append('diff', self.left, self.right)
if self.left_only:
self.left_only.sort()
output.append('Only in', self.left, ':',
self.left_only)
if self.right_only:
self.right_only.sort()
output.append('Only in', self.right, ':',
self.right_only)
if self.same_files:
self.same_files.sort()
output.append('Identical files :', self.same_files)
if self.diff_files:
self.diff_files.sort()
output.append('Differing files :', self.diff_files)
if self.funny_files:
self.funny_files.sort()
output.append('Trouble with common files :',
self.funny_files)
if self.common_dirs:
self.common_dirs.sort()
output.append('Common subdirectories :',
self.common_dirs)
if self.common_funny:
self.common_funny.sort()
output.append('Common funny cases :',
self.common_funny)
More information about the Python-list
mailing list