difflib
The difflib module provides functions and classes for computing differences between lists of strings. The module duplicates the functionality provided by many variants of the popular Unix diff command that’s used to compare files.
context_diff(a, b [, fromfile [, tofile [, fromfiledate [, tofiledate [, n [, lineterm]]]]]])
Given two lists of strings, a and b, this function returns a generator object that produces output corresponding to a context-sensitive difference. The output produced by this function is similar to the following:
*** fromfile fromfiledate --- tofile tofiledate *************** *** 1,9 **** context context context ! modified line context - deleted line context context context --- 1,9 ---- context context context ! ...
Get Python: Essential Reference, Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.