Another way of doing this might be to use the module difflib to calculate the differences. It has a sequence matcher under it which has the function get_matching_blocks
difflib is included with python. On May 29, 2:02 pm, Chris <[EMAIL PROTECTED]> wrote: > On May 29, 10:36 am, loial <[EMAIL PROTECTED]> wrote: > > > I have a requirement to compare 2 text files and write to a 3rd file > > only those lines that appear in the 2nd file but not in the 1st file. > > > Rather than re-invent the wheel I am wondering if anyone has written > > anything already? > > How large are the files ? You could load up the smallest file into > memory then while iterating over the other one just do 'if line in > other_files_lines:' and do your processing from there. By your > description it doesn't sound like you want to iterate over both files > simultaneously and do a line for line comparison because that would > mean if someone plonks an extra newline somewhere it wouldn't gel. -- http://mail.python.org/mailman/listinfo/python-list