[Tutor] Trying tio emulate "diff" command of UNIX - please help
Senthil_OR at Dell.com
Senthil_OR at Dell.com
Fri Oct 6 15:11:32 CEST 2006
Hi,
Your program does not emulate the diff command of Unix.
Please do a diff in unix and experience yourselves.
Where is cmp_res = stringcmp(string1[i],string2[i])
stringcmp() function written?
Moreover, if you Python Documentation install (or python.org accessible) search for difflib and Differ Example.
That should give you a good start.
Thanks,
--
Senthil
________________________________
From: tutor-bounces at python.org [mailto:tutor-bounces at python.org] On Behalf Of Asrarahmed Kadri
Sent: Friday, October 06, 2006 6:09 PM
To: tutor at 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
Can someone help me with what is wrong in this code; when I am running it gets stuck.
thanks in anticipation.
Regards,
Asrar
--
To HIM you shall return.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20061006/9fa1ae77/attachment.htm
More information about the Tutor
mailing list