zoukankan      html  css  js  c++  java
  • 文件差异对比

    脚本:

    #!/usr/bin/python

    import difflib
    import sys
    from python.auto.yunwei.diff1 import text1_lines
    try:
    textfile1=sys.argv[1]
    textfile2=sys.argv[2]
    except Exception,e:
    print "Error:"+str(e)
    print "Usage: diff3.py filename1 filename2"
    sys.exit()
    def readfile(filename):
    try:
    filehandle=open(filename,'rb')
    text=filehandle.read().splitlines()
    filehandle.close()
    return text
    except IOError as error:
    print 'read file error:'+str(error)
    sys.exit()

    if textfile1=="" or textfile2=='':
    print "Usage:diffe.py filename1 filename2"
    sys.exit()
    text1_lines=readfile(textfile1)
    text2_lines=readfile(textfile2)
    d=difflib.HtmlDiff()
    print d.make_file(text1_lines, text2_lines)

     

     

     

    第一种方法

    import difflib
    text1='''text1:
    This module provides
    defflib document v7.4
    add string
    '''
    text1_lines=text1.splitlines()
    text2='''
    this module provedess
    defflib document v7.5
    '''
    text2_lines=text2.splitlines()
    d=difflib.Differ()
    deff=d.compare(text1_lines, text2_lines)
    print ' '.join(list(deff))

    第二种方法:用浏览器阅读

    import difflib
    text1='''text1:
    This module provides
    defflib document v7.4
    add string
    '''
    text1_lines=text1.splitlines()
    from difflib import HtmlDiff
    text2='''
    this module provedess
    defflib document v7.5
    '''
    text2_lines=text2.splitlines()
    d=HtmlDiff()
    diffs=d.make_file(text1_lines,text2_lines)
    print diffs

  • 相关阅读:
    计算机系统概述
    Qt学习--初学注意事项
    Qt实现一个简单的TextEditor
    Qt 用户登录界面
    C++ 模板
    多态与虚函数
    继承与派生
    C++ 运算符重载
    web安全-点击劫持
    web安全问题-cookie
  • 原文地址:https://www.cnblogs.com/mmdln/p/9034966.html
Copyright © 2011-2022 走看看