Newbie question on 'cmpfiles':

Srihari Vijayaraghavan harisri at bigpond.com
Wed Dec 6 05:05:31 EST 2000


Oldayz wrote:

> On Tue, 05 Dec 2000 05:59:02 GMT, harisri at my-deja.com
> <harisri at my-deja.com> wrote:
> >Hello,
> >
> >I am a newbie user to python 2.0
> >
> >Can someone help me by explaining 'cmpfiles' function with a simple
> >example?
> >
> >I am trying to compare 2 directories, but not sure about the syntaxof
> >this function. The "Python Reference Library" did not help me on this.
> >
> >[What does "common" mean in "cmpfiles(dir1, dir2, common)"?]
> 
> This function is used to compare *files*, not directories. Multiple files
> in these directories.
> 
> To compare directories, use dircmp class:
> 
> dircmp (a, b[, ignore[, hide]])
> Construct a new directory comparison object, to compare the
> directories a and b. ignore is a list of names to ignore, and
> defaults to ['RCS', 'CVS', 'tags']. hide is a list of names to
> hid, and defaults to [os.curdir, os.pardir].
> 
> report ()
> Print (to sys.stdout) a comparison between a and b.
> 
> etc.. It's in 2.0 lib ref under filecmp
> 
> >
> >Thanks in advance,
> >Hari.
> >
> >
> >Sent via Deja.com http://www.deja.com/
> >Before you buy.
> 
> 
Hello Andrei,

Thanks. However I am having some problem while using "dircmp" class.

I have the following 2 (identical) directories under my home directory: 
/home/hari/python1 and /home/hari/python2. 

I am getting few error messages, only while using the following attributes: 
diff_files, report(), report_partial_closure(), and report_full_closure().

I am enclosing the error messages for your reference. Am I doing something 
wrong?

Python 2.0 (#1, Oct 16 2000, 18:10:03)
[GCC 2.95.2 19991024 (release)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> from filecmp import *
>>> x=dircmp("/home/hari/python1", "/home/hari/python2")
>>> x.left_list
['about.html', 'acks.html', 'api', 'dist', 'doc', 'ext', 'icons', 
'index.html',
'inst', 'lib', 'mac', 'modindex.html', 'ref', 'tut']
>>> x.right_list
['about.html', 'acks.html', 'api', 'dist', 'doc', 'ext', 'icons', 
'index.html',
'inst', 'lib', 'mac', 'modindex.html', 'ref', 'tut']
>>> x.common
['ref', 'ext', 'acks.html', 'inst', 'api', 'mac', 'about.html', 
'modindex.html', 'tut', 'doc', 'icons', 'lib', 'dist', 'index.html']
>>> x.left_only
[]
>>> x.right_only
[]
>>> x.common_dirs
['ref', 'ext', 'inst', 'api', 'mac', 'tut', 'doc', 'icons', 'lib', 'dist']
>>> x.common_files
['acks.html', 'about.html', 'modindex.html', 'index.html']
>>> x.same_files
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/local/lib/python2.0/filecmp.py", line 147, in __getattr__
    self.phase3()
  File "/usr/local/lib/python2.0/filecmp.py", line 214, in phase3
    xx = cmpfiles(self.left, self.right, self.common_files)
  File "/usr/local/lib/python2.0/filecmp.py", line 288, in cmpfiles
    res[_cmp(ax, bx, shallow, use_statcache)].append(x)
TypeError: too many arguments; expected 2, got 4                            
>>> x.report()
diff /home/hari/python1 /home/hari/python2
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/local/lib/python2.0/filecmp.py", line 241, in report
    if self.same_files:
  File "/usr/local/lib/python2.0/filecmp.py", line 147, in __getattr__
    self.phase3()
  File "/usr/local/lib/python2.0/filecmp.py", line 214, in phase3
    xx = cmpfiles(self.left, self.right, self.common_files)
  File "/usr/local/lib/python2.0/filecmp.py", line 288, in cmpfiles
    res[_cmp(ax, bx, shallow, use_statcache)].append(x)
TypeError: too many arguments; expected 2, got 4                            
 >>> x.report_partial_closure()
diff /home/hari/python1 /home/hari/python2
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/local/lib/python2.0/filecmp.py", line 258, in 
report_partial_closure
    self.report()
  File "/usr/local/lib/python2.0/filecmp.py", line 241, in report
    if self.same_files:
  File "/usr/local/lib/python2.0/filecmp.py", line 147, in __getattr__
    self.phase3()
  File "/usr/local/lib/python2.0/filecmp.py", line 214, in phase3
    xx = cmpfiles(self.left, self.right, self.common_files)
  File "/usr/local/lib/python2.0/filecmp.py", line 288, in cmpfiles
    res[_cmp(ax, bx, shallow, use_statcache)].append(x)
TypeError: too many arguments; expected 2, got 4
>>> x.report_full_closure()
diff /home/hari/python1 /home/hari/python2
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/local/lib/python2.0/filecmp.py", line 264, in 
report_full_closure
    self.report()
  File "/usr/local/lib/python2.0/filecmp.py", line 241, in report
    if self.same_files:
  File "/usr/local/lib/python2.0/filecmp.py", line 147, in __getattr__
    self.phase3()
  File "/usr/local/lib/python2.0/filecmp.py", line 214, in phase3
    xx = cmpfiles(self.left, self.right, self.common_files)
  File "/usr/local/lib/python2.0/filecmp.py", line 288, in cmpfiles
    res[_cmp(ax, bx, shallow, use_statcache)].append(x)
TypeError: too many arguments; expected 2, got 4                            
    
Thanks in advance,

Hari.      



More information about the Python-list mailing list