A simply newbie question about ndiff

Neville Franks nospam-readonly at getsoft.com
Mon Apr 22 00:12:56 EDT 2002


Thanks for that Emile.

One thing I've noticed now is for larger files (73,000 lines) ndiff can take
several minutes on my 1G PC, but that is another issue again. I assume the
fact that it is being interpreted has quite a bit to do with this.


"Emile van Sebille" <emile at fenx.com> wrote in message
news:ddLw8.50678$HH5.4019 at rwcrnsc51.ops.asp.att.net...
> Neville Franks
> > Ok thanks. I've installed 2.2 and ndiff is available but I'm still
> confused.
> > I thought that Tim's original ndiff compared files, but the one in
> difflib
> > compares lists of strings. Does this mean I somehow need to read the
> files
> > into lists of strings and then call ndiff. A short example of how to
> use
> > ndiff to compare two files would be greatly appreciated.
> >
>
> David pointed you to python22/tools/scripts/difflib.py.  In it you'll
> find this example of how to use it:
>
> def fopen(fname):
>     try:
>         return open(fname, 'r')
>     except IOError, detail:
>         return fail("couldn't open " + fname + ": " + str(detail))
>
> # open two files & spray the diff to stdout; return false iff a problem
> def fcompare(f1name, f2name):
>     f1 = fopen(f1name)
>     f2 = fopen(f2name)
>     if not f1 or not f2:
>         return 0
>
>     a = f1.readlines(); f1.close()
>     b = f2.readlines(); f2.close()
>     for line in difflib.ndiff(a, b):
>         print line,
>
>     return 1
>
>
> You could then say something like:
>
> fcompare(r'c:\CrunchyFrog.txt', r'c:\CrunchyFfruug.txt')
>
> Assuming-you-were-casting-Peter-Sellers-in-a-skit-ly y'rs,
>
>
> --
>
> Emile van Sebille
> emile at fenx.com
>
> ---------
>





More information about the Python-list mailing list