Skip to content

difflib#

より高機能なものは(html 形式で出力)以下が参考に。

unified_diff#

  • difflib.unified_diff(a, b, fromfile='', tofile='', fromfiledate='', tofiledate='', n=3, lineterm='\n')
sample
import difflib


s1 = ['bacon\n', 'eggs\n', 'ham\n', 'guido\n']
s2 = ['python\n', 'eggy\n', 'hamster\n', 'guido\n']
sys.stdout.writelines(unified_diff(s1, s2, fromfile='before.py', tofile='after.py'

difflib のコマンドラインインターフェース#