[Tutor] Trying tio emulate "diff" command of UNIX - please help

Asrarahmed Kadri ajkadri at googlemail.com
Fri Oct 6 14:39:07 CEST 2006


# 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/c754e3ba/attachment.html 


More information about the Tutor mailing list