Надо пословно сравнить 2 файла (использую difflib) и вывести удобочитаемый вариант. Пробовал по-разному, но все не так.
Возьмем, скажем файлы со следующим содержимым.
context and numlines are both optional keyword arguments. Set context to True when contextual differences are to be shown, else the default is False to show the full files. numlines defaults to 5. When context is True numlines controls the number of context lines which surround the difference highlights. When context is False numlines controls the number of lines which are shown before a difference highlight when using the “next” hyperlinks (setting to zero would cause the “next” hyperlinks to place the next difference highlight at the top of the browser without any leading context).
context and numlines are both compulsory excellent keyword arguments. Set numlines to False when text differences are to be shown, else the default is True (Fig. 5) to show the full files. numlines defaults to 50. When context is True numlines controls the number of context lines (100500) which surround the difference highlights. When context is True numlines controls the number of lines which are shown before a difference light when using the “next” hyperlinks (setting to zero would cause the “next” hyperlinks to place the next difference highlight at the top of the browser without any leading context).
1. Вывод в html.
f1 = open('4','r')
f2 = open('5','r')
text1 = f1.read().split(' ')
text2 = f2.read().split(' ')
diff = difflib.HtmlDiff().make_file(text1, text2)
print diff
2. Вывод как текст с помощью compare
d = difflib.Differ()
result = list(d.compare(text1, text2))
sys.stdout.writelines(result)
Получается следующее:
context and numlines are both- optional+ compulsory+ excellent keyword arguments. Set- context+ numlines to- True+ False when- contextual+ text differences are to be shown, else the default is- False+ True+ (Fig.+ 5) to show the full files. numlines defaults to- 5.+ 50.? +
When context is True numlines controls the number of context lines+ (100500) which surround the difference highlights. When context is- False+ True numlines controls the number of lines which are shown before a difference- highlight+ light when using the “next” hyperlinks (setting to zero would cause the “next” hyperlinks to place the next difference highlight at the top of the browser without any leading context).
context and numlines are both [-optional-] {+compulsory excellent+} keyword arguments. Set [-context-] {+numlines+} to [-True-] {+False+} when [-contextual-] {+text+} differences are to be shown, else the default is [-False-] {+True (Fig. 5)+} to show the full files. numlines defaults to [-5.-] {+50.+} When context is True numlines controls the number of context lines {+(100500)+} which surround the difference highlights. When context is [-False-] {+True+} numlines controls the number of lines which are shown before a difference [-highlight-] {+light+} when using the “next” hyperlinks (setting to zero would cause the “next” hyperlinks to place the next difference highlight at the top of the browser without any leading context).
1. Beautiful is better than ugly.
- 2. Explicit is better than implicit.
- 3. Simple is better than complex.
+ 3. Simple is better than complex.
? ++
- 4. Complex is better than complicated.
? ^ ---- ^
+ 4. Complicated is better than complex.
? ++++ ^ ^
+ 5. Flat is better than nested.
Разница на лицо. Как мне исправить код, так чтобы результат читался получше (интересует вывод и в виде текста, и в виде html, но прежде всего html)?