On 04/01/12 14:54, Joel Goldstick wrote:
two files' content is equal, just print "equal". Else, print the
rows And column number of the first different position.
while True:
line = f1.readline()
if line != f2.readline():
print lineNum, " : ", line
# in here I believe you need a bit more. You now know the lines are
not equal, but the exercise requires the line number and column number
Oops, I didn't notice the column bit...sorry.
# To do that, you need to do something similar to what Alan has shown
for i, c in enumerate(line): #enumerate iterates over the
if line2[i] != c: # line2[i] is the
print "The file differs at line %d, column %d" % lineNum, i
Yep, that ought to work.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor