From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Asrarahmed Kadri
Sent: Friday, October 06, 2006 6:09 PM
To: tutor@python.org
Subject: [Tutor] Trying tio emulate "diff" command of UNIX - please help
# This program emulates the diff command of UNIX
import sys
from stringCompare import stringcmp # this is a
module which has stringcmp function that compares two strings
fname1 = raw_input("Enter a file name to be read:\t")
fname2 = raw_input("Enter a file name to be read:\t")
fd1 = open(fname1,"r")
fd2 = open(fname2,"r")
done = 0
line_counter = 0
while not done:
aLine1 =
fd1.readline()
aLine2 =
fd2.readline()
if (aLine1 == "" or
aLine2 == ""): # test whether you have reached the end of
file
done = 1
else:
line_counter +=
1 #
get the line number
string1 =
aLine1.split() # split the line
into a list containing words
string2 = aLine2.split ()
len1 = len(string1)
len2 =
len(string2)
if len1 >
len2:
t =
len1
else:
t
= len2
i = 0
while (i <
t):
cmp_res =
stringcmp(string1[i],string2[i])
if cmp_res !=
0:
column
= i
done =
1
print "The difference is lies in the ", line_counter ,"line and column ",
column
--
To HIM you shall return.
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor