ndiff feature request
Willem Broekema
news at pastelhorn.com
Mon Feb 26 18:48:46 EST 2001
The new 'ndiff.py' module (./tools/scripts/ndiff.py) contains among
others this function "fcompare(f1name, f2name)" that opens two files
given their names, readlines() them, and creates a 'diff' of the lists:
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()
cruncher = SequenceMatcher(IS_LINE_JUNK, a, b)
for tag, alo, ahi, blo, bhi in cruncher.get_opcodes():
...
How about separating these two tasks, by creating a function, say,
"lcompare(a,b)" that takes two lists as argument, and does the things
from "cruncher = ..." onwards. Then, fcompare could call that function
after the files are opened and checked.
This would make other ways of diff-ing possible without having to write
to a temporary file first. Things like diffing
urllib.urlopen("http://someurl").readlines() with a cached list object,
for example.
Or is there already an easy way to do this?
- Willem
More information about the Python-list
mailing list