Trying to compare files opened using 'with open...' in Python 2.4 gives a SyntaxError -


how can compare 2 files in python 2.4.4? files different lengths.

we have python 2.4.4 on our servers. use difflib.unified_diff() function can't find examples work python 2.4.4.

all versions have seen on stack overflow contain following:

with open("filename1","r+") f1:   open ("filename2","r+") f2:     difflib.unified_diff(..........) 

the problem have within version 2.4.4 with open ... generates syntaxerror. stay away using system call diff or sdiff possible.

the with statement introduced in python 2.5. it's straightforward want without it, though:

a.txt

this file 'a'.  lines common, lines unique, want pony, poetry awful. 

b.txt

this file 'b'.  lines common, want pony, nice 1 swishy tail, poetry awful. 

python

import sys  difflib import unified_diff  = 'a.txt' b = 'b.txt'  a_list = open(a).readlines() b_list = open(b).readlines()  line in unified_diff(a_list, b_list, fromfile=a, tofile=b):     sys.stdout.write(line) 

output

--- a.txt  +++ b.txt  @@ -1,6 +1,6 @@ -this file 'a'. +this file 'b'.  lines common, -some lines unique, want pony, +a nice 1 swishy tail, poetry awful. 

Popular posts from this blog

html/hta mutiple file in audio player -

debugging - Reference - What does this error mean in PHP? -