Ignoring spaces in python diff

Is there an elegant way to ignore spaces in diff in python (using difflib or any other module)? Maybe I missed something, but I looked through the documentation and could not find explicit support for this in difflib.

My current solution is to simply split my text into lists of words and then split them:

d.compare(("".join(text1_lines)).split(), ("".join(text2_lines)).split()) 

The disadvantage of this is that if you need a phased differences report, not just one word, you must combine the diff output with the source text of the file. It is easy to do, but a little uncomfortable.

+4
source share

Source: https://habr.com/ru/post/1495373/


All Articles