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

inshu chauhan insideshoes at gmail.com
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:
        continue
    else:
        ix = sp[0].strip()
        iy = sp[1].strip()
        print ix, iy

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

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

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

f1.close()
f2.close()
nf.close()


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: <http://mail.python.org/pipermail/python-list/attachments/20130128/423ff754/attachment.html>


More information about the Python-list mailing list