[Originally posted by ginanguyen] Hi, I have two small input files about 200 Kbytes each. The files contain various columns but the same number of rows. The columns are separated from one another by absolutely one space. I need to merge some columns of one file to those of the other (rows are correspondent) using "shelve": import fileinput import shelve import string def mkRexShel(): File1 = open("file1.txt", 'r') File2 = open("file2.txt", 'r') flSh = shelve.open("flShelve") # 1. from the Beam Proc header file Line1 = File1.readline() Line2 = File2.readline() while (xLine != " " or xLine != "") and (rLine != " " or rLine != "") : string.replace(Line1, " ", "") string.replace(Line2, " ", "") Ln1 = string.split(Line1, ' ') Ln2 = string.split(Line2, ' ') if len(Ln1) > 1 and len(Ln2) > 1 : xStr = Ln1[1] + Ln1[2] + Ln1[3] rStr = Ln2[1] + Ln2[2] + Ln2[3] if xStr == rStr : del Ln2[0:3] Ln1.extend(Ln2) flSh[xStr] = Ln1 Line1 = File1.readline() Line2 = File2.readline() File1.close() File2.close() flSh.close() When I execute this little script using "mkRexShel()". It's hung! What are wrong with my script? Thanks.
|