# -*- coding:utf-8 -*-
import difflib
import sys

def readfile(filename):
    try:
        fileHandle = open(filename, 'r+')
        text = fileHandle.read().splitlines()
        fileHandle.close()
        return text
    except IOError as error:
        print('Read file Error:' + str(error))
        sys.exit()

def savediffile():
    text1_lines = readfile(textfile1)
    text2_lines = readfile(textfile2)
    d = difflib.HtmlDiff()
    with open('difffile.html','w') as f:
        f.write(d.make_file(text1_lines, text2_lines))

if __name__ == '__main__':
    try:
        textfile1 = sys.argv[1]
        textfile2 = sys.argv[2]
        savediffile()

    except Exception as e:
        print("Error:" + str(e))
        print("Usage: 3.py filename1 filename2")
        sys.exit()

 

相关文章:

  • 2021-05-23
  • 2022-12-23
  • 2021-12-11
  • 2022-12-23
  • 2021-11-07
  • 2021-10-05
  • 2021-10-09
猜你喜欢
  • 2021-12-09
  • 2021-08-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-19
  • 2021-06-18
相关资源
相似解决方案