The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

import-bot (20211) [Avatar] Offline
[Originally posted by ginanguyen]


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 ="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]
flSh[xStr] = Ln1

Line1 = File1.readline()
Line2 = File2.readline()


When I execute this little script using "mkRexShel()". It's hung! What are
wrong with my script? Thanks.
import-bot (20211) [Avatar] Offline
Re: Hang in file processing
[Originally posted by ginanguyen]

Actually, I have found out that Python does not like
my while statement:

while (<comparison> or <comparison>smilie
and (<comparison> or <comparison>smilie :

Because if I took the parantheses out and reduce my
condition to

while <condition> and <condition> :

It works fine. Do you know why? Thanks.