Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing two text files in python

Tags:

python

I need to compare two files and redirect the different lines to third file. I know using diff command i can get the difference . But, is there any way of doing it in python ? Any sample code will be helpful

like image 704
tazim Avatar asked Jun 15 '10 06:06

tazim


1 Answers

check out difflib

This module provides classes and functions for comparing sequences. It can be used for example, for comparing files, and can produce difference information in various formats, including HTML and context and unified diffs[...]

A command-line example in http://docs.python.org/library/difflib.html#difflib-interface

like image 139
remosu Avatar answered Oct 17 '22 11:10

remosu