You don't really say what you are trying to accomplish. Do you want to identify the common text, or find the pieces that differ?

If the common text is always the same and you know it ahead of time, you can just search the lines of each file to find it.

If you need to identify the common part, difflib might be useful. There is an example on this page of finding matching blocks of two sequences:
http://docs.python.org/lib/sequencematcher-examples.html


In your case the sequences will be lists of lines rather than strings (which are sequences of characters)

Kent

Ertl, John wrote:
All,

I have two text files that should contain a section of text that is the
same. Luckily the section of text has a defined beginning and end. It
looks like the most straightforward thing would be to read the targeted text
from each file (only 50 lines or so) into lists and then compare the lists.
I would think I could use sets to find a unique list (hopefully there would
not be anything)...or I could do line by line comparison. Any advise on
what is the better method. Should I avoid the list comparison approach...is
there a built in way of comparing entire files instead of dealing explicitly
with the lines?


Thanks,

John Ertl _______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor



_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Reply via email to