Questions tagged [difflib]

A python module, provides tools for computing and working with differences between sequences, especially useful for comparing text. Includes functions that produce reports using several common difference formats.

A python module which 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.

341 questions
5
votes
2 answers

ImportError :No module named difflib_data

I am working with python 3.4 in windows 7.Trying to compare two text files and i want to report the differences in them using difflib. Following is the code m using: import difflib from difflib_data import * with open("s1.txt") as f, open("s2.txt")…
Maxxie
  • 397
  • 1
  • 4
  • 14
5
votes
0 answers

What stronger alternatives are there to difflib?

I am working on script that needs to be able to track revisions. The general idea is to give it a list of tuples where the first entry is the name of a field (ie "title" or "description" etc.), the second entry is the first version of that field,…
wnnmaw
  • 5,444
  • 3
  • 38
  • 63
5
votes
3 answers

Get close string matches considering deletion - python

Is there a way to let difflib consider deletion in string matching? I've tried the difflib.get_close_matches() but it doesn't consider strings with lower length in the close matches output. E.g. from difflib import get_close_matches as gcm x =…
alvas
  • 115,346
  • 109
  • 446
  • 738
5
votes
0 answers

Can difflib's charjunk be used to ignore whitespace?

I'd like to compare differences between two lists of strings. For my purposes, whitespace is noise and these differences do not need to be shown. Reading into difflib's documentation, "the default [for charjunk] is module-level function…
Mike T
  • 41,085
  • 18
  • 152
  • 203
4
votes
2 answers

Using python difflib to compare more than two files

I would like to get an overview over e.g. the ldd dependency list of multiple (3+) computers by comparing them with each other and highlighting the differences. For example, if I have a dict that looks as following: my_ldd_outputs = { …
Yes
  • 339
  • 3
  • 19
4
votes
2 answers

Python difflib gnu patch compatibility

It's possible to create patch with python module difflib which is compatible with GNU patch? I tried to use unified_diff and context_diff and also tried to specify lineterm as "\n" but I'm still gettings this error: [intense@Singularity Desktop]$…
intense
  • 197
  • 1
  • 9
4
votes
1 answer

Python, compare two sentence by words using difflib

Im using difflib and tried to compare the two sentence and get the difference. Somewhat like this. i have this code but instead of word by word it analyzed letter by letter. import difflib # define original text # taken from:…
Mark Anthony Libres
  • 906
  • 1
  • 7
  • 14
4
votes
3 answers

auto-correct the words from the list in python

I want to auto-correct the words which are in my list. Say I have a list kw = ['tiger','lion','elephant','black cat','dog'] I want to check if these words appeared in my sentence. If they are wrongly spelled I want to correct them. I don't intend…
Sociopath
  • 13,068
  • 19
  • 47
  • 75
4
votes
1 answer

Create unified diff text for diff2html in browser

Is there a library that produces unified diff from two strings that diff2html can use? I've tried difflib but the output does not seem to fit the requirements that diff2html needs. I need a .js library I can import in the webpage to produce diffs…
4
votes
1 answer

How does Python 3.6 SequenceMatcher().get_matching_blocks() work?

I am trying to use SequenceMatcher.ratio() to get the similarity of two strings: "86418648" and "86488648": >>> SequenceMatcher(None,"86418648","86488648").ratio() 0.5 The ratio returned is 0.5, which is much lower than I expected because there is…
Jessie
  • 41
  • 1
  • 5
4
votes
3 answers

Python Difflib Deltas and Compare Ndiff

I was looking to do something like what I believe change control systems do, they compare two files, and save a small diff each time the file changes. I've been reading this page: http://docs.python.org/library/difflib.html and it's not sinking in…
NealWalters
  • 17,197
  • 42
  • 141
  • 251
4
votes
2 answers

Get standard gnu diff output from Python's difflib?

Is there any way to get the following output (especially the 1,4c1,4 syntax) from Python's difflib? diff foo baz 1,4c1,4 < 'asdf' < 'asdf' < 'asdf' < 'asdf' --- > asdf > asdf > asdf > asdf
kev
  • 8,928
  • 14
  • 61
  • 103
4
votes
5 answers

Comparing two columns of a csv and outputting string similarity ratio in another csv

I am very new to python programming. I am trying to take a csv file that has two columns of string values and want to compare the similarity ratio of the string between both columns. Then I want to take the values and output the ratio in another…
Jimmy
  • 43
  • 1
  • 5
4
votes
1 answer

What is the standard way to represent subsequent changes in a text and to work with this representation using Python?

Assume that I have some text (for example given as a string). Later I am going to "edit" this text, which means that I want to add something somewhere or remove something. In this way I will get another version of the text. However, I do not want to…
Roman
  • 124,451
  • 167
  • 349
  • 456
4
votes
3 answers

Determine where documents differ with Python

I have been using the Python difflib library to find where 2 documents differ. The Differ().compare() method does this, but it is very slow - atleast 100x slower for large HTML documents compared to the diff command. How can I efficiently determine…
hoju
  • 28,392
  • 37
  • 134
  • 178
1 2
3
22 23