[Tutor] how to join two different files

Alan Gauld alan.gauld at btinternet.com
Fri Jul 17 20:59:11 CEST 2009


<amrita at iisermohali.ac.in> wrote

> but it is priniting second file after first, whereas i want to join them
> columwise like:---
> 
> FileA  FileB   FileC
> 12      14     12  14
> 15  +   16  =  15  16
> 18      17     18  17
> 20      19     20  19
> 

I'm not sure what the plus sign in the second line signifies 
but otherwise it looks like you will need to process each file 
line by line and concatenate each string.

for line1 in fileA:
     line2 = fileB.readline()
     fileC.write("%s\t%s" % line1,line2)


You might need to strip the lines before writing them...


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list