<div>Thanks Alan, but can you please explain me what this line does:</div>
<div>diff = [t1==t2 for t1,t2 in zip(line1,line2)].index(False)<br> </div>
<div><br><br> </div>
<div><span class="gmail_quote">On 10/6/06, <b class="gmail_sendername">Alan Gauld</b> <<a href="mailto:alan.gauld@btinternet.com">alan.gauld@btinternet.com</a>> wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Some general thoughts:<br><br>> import sys<br>> from stringCompare import stringcmp # this is a module which has
<br>> stringcmp<br>><br>> fname1 = raw_input("Enter a file name to be read:\t")<br>> fname2 = raw_input("Enter a file name to be read:\t")<br>><br>> fd1 = open(fname1,"r")<br>
> fd2 = open(fname2,"r")<br>><br>><br>> done = False<br><br>Use Boolean value instead of 1/0<br><br>> line_counter = 0<br>> while not done:<br>> aLine1 = fd1.readline()<br>> aLine2 =
fd2.readline()<br>><br>> if (aLine1 == "" or aLine2 == ""): # test whether you have<br>> reached the<br>> end of file<br>> done = 1<br><br>assign directly to done, using a boolean test:
<br><br>done = not (aLine1 and aLine2)<br><br>and miss out the if/else test.<br><br>> line_counter += 1 # get the line number<br>> string1 = aLine1.split() # split the line into a
<br>> list containing words<br>> string2 = aLine2.split()<br><br>Not sure why you are splitting the lines into words.<br>You call them columns but they are really words of<br>varying length. Why not just compare the lines as a whole?
<br><br>if aLine1 != aLine2:<br> print "The difference lies in line", line_counter<br><br>Then you can find the first characters that differ:<br><br> diff = [t1==t2 for t1,t2 in zip(line1,line2)].index(False)
<br> print "and start at character", diff<br><br>It's not exactly equivalent to your code of course but it seems to me<br>to be more accurate...<br><br>If you must use words, apply the spolit only when you know its needed:
<br><br> words1 = aLine1.split()<br> words2 = aLine2.split()<br> diff = [w1==w2 for w1,w2 in zip(words1,words2)].index(False)<br> print "and start at word",diff<br><br>HTH,<br><br><br>--<br>Alan Gauld
<br>Author of the Learn to Program web site<br><a href="http://www.freenetpages.co.uk/hp/alan.gauld">http://www.freenetpages.co.uk/hp/alan.gauld</a><br><br><br>_______________________________________________<br>Tutor maillist -
<a href="mailto:Tutor@python.org">Tutor@python.org</a><br><a href="http://mail.python.org/mailman/listinfo/tutor">http://mail.python.org/mailman/listinfo/tutor</a><br></blockquote></div><br><br clear="all"><br>-- <br>To HIM you shall return.