Reading data from 2 different files and writing to a single file

inshu chauhan insideshoes at
Mon Jan 28 14:31:31 CET 2013

In the code below I am trying to read 2 files f1 and f2 , extract some data
from them and then trying to write them into a single file that is 'nf'.

import cv
f1 = open(r"Z:\modules\Feature_Vectors_300.arff")
f2 = open(r"Z:\modules\Feature_Vectors_300_Pclass.arff")
nf = open(r"Z:\modules\trial.arff", "w")

for l in f1:
    sp = l.split(",")

    if len(sp)!= 12:
        ix = sp[0].strip()
        iy = sp[1].strip()
        print ix, iy

       for s in f2:
            st = s.split(",")

            if len(st)!= 11:
                clas = st[10].strip()

             print ix, iy, clas
             print >> nf, ix, iy, clas


I think my code is not so correct , as I am not getting desired results and
logically it follows also but I am stuck , cannot find a way around this
simple problem of writing to a same file.. Please suggest some good
pythonic way I can do it..

Thanks in Advance
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list