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: [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

 
 
 
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.
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to