[Tutor] Getting two files to print

Philip Carl plc at med.unc.edu
Mon Jul 18 22:25:53 CEST 2005


I have no more hair to pull out, so I'm asking the group for help on a 
VERY simple question.  I have two very similar text files to read-one 
with the final letters in the name 10%.txt and the other 20%.txt.  I've 
written the following simple code to read these two files:

# Program to read and print two text fiiles
fileNameA = 
'c:/Python24/outputs_1ubq_alignments/output_1ubq_alignments_10%.txt'   
#text file one
firstFile=open (fileNameA,'r')
inFileLeftA = 1 #more file to read
inLineA=[0]
while inFileLeftA:
    inLineA = firstFile.readline()
    if (inLineA == ''):
        infileLeftA = 0 #if empty line end of first file
       
    else:
        print inLineA
firstFile.close()

fileNameB = 
'c:/Python24/outputs_1ubq_alignments/output_1ubq_alignments_20%.txt'  
#text file two
secondFile=open (fileNameB,'r')
inFileLeftB = 1 #more file to read
inLineB=[0]
while inFileLeftB:
    inLineB = secondFile.readline()
    if (inLineB == ''):
        infileLeftB = 0 #if empty line end of second file
   
    else:
         print inLineB
secondFile.close()

I realize that I probably ought to be able to code this more 
efficiently, but as a rank beginner I am less worried about efficiency 
than output.  I can't seem to get BOTH files to print  when run as 
presented, although when I split the program into two programs each file 
seems to print OK.  As written here however,  I can get the first but 
not the second textfile to print. What am I doing wrong?. 

Philip Carl
Associate Professor of Pharmacology
1026A Mary Ellen Jones Bld. CB 7365
University of North Carolina Medical School
Chapel Hill, NC 27599
Phone: 919-966-3544
FAX: 919-966-5640




More information about the Tutor mailing list