percentage difference between two text files

algorithm, language-agnostic, linux, python

Solution

You can use difflib.SequenceMatcher ratio method

From the documentation:

Return a measure of the sequences’ similarity as a float in the range [0, 1].

For example:

from difflib import SequenceMatcher
text1 = open(file1).read()
text2 = open(file2).read()
m = SequenceMatcher(None, text1, text2)
m.ratio()

Problem

I know that I can use cmp, diff, etc to compare two files, but what I am looking for is a utility that gives me percentage difference between two files. if there is no such utility, any algorithm would do fine too. I have read about fuzzy programming, but I have not quite understand it.

Original source