zhasm
8/9/2012 - 11:46 AM

compare 2 blocks of text

compare 2 blocks of text

#!/usr/bin/env python
# -*- encoding: utf-8 -*-

from difflib import unified_diff

def getRawInput(name):
    ret=[]
    ret.append(raw_input("Please copy a bunch of lines as %s, and press Enter && Ctrl-D to end: \n\n" % name ).strip())
    while True:
        try:
            ret.append(raw_input().strip())
        except EOFError:
            break
    return ret

if __name__ == '__main__':
    a=getRawInput('A')
    print '\n', '='*32, '\n'
    b=getRawInput('B')
    for line in unified_diff(a, b):
        print line