IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    [Python] 利用HTML页面查看字符串差异

    showerlee发表于 2015-09-28 08:21:19
    love 0

    # vi diff.py

    #!/usr/bin/env python
    
    import difflib
    
    text1 = '''text1:
    This mudule provides classes and fuctions for comparing sequences.
    including HTML and context and unified diffs.
    difflib document v7.4
    add string
    '''
    text1_lines = text1.splitlines()
    
    text2 = '''text2:
    This mudule provides classes and fuctions for Comparing sequences.
    including HTML and  context and unified diffs.
    difflib document v7.5
    ''' 
    text2_lines = text2.splitlines()
    
    #d = difflib.Differ()
    #diff = d.compare(text1_lines, text2_lines)
    
    #print '\n'.join(list(diff))
    
    d = difflib.HtmlDiff()
    print d.make_file(text1_lines, text2_lines)

    运行脚本并重定向为一个html静态页面

    # chmod 755 diff.py

    # ./diff.py  > diff.html

    浏览器打开该页面

    如图:

    QQ20150928-1

    声明: 本文采用 CC BY-NC-SA 3.0 协议进行授权
    转载请注明来源:一路向北的博客
    本文链接地址:http://www.showerlee.com/archives/1580


沪ICP备19023445号-2号
友情链接