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

inshu chauhan insideshoes at gmail.com
Mon Jan 28 15:12:56 CET 2013


Yes Chris, I understand, My Original code was

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

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


    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()

where f1 contains something like :

297, 404, , ....
298, 404, , ......
299, 404, .....
.....  ......
295, 452, ....

and f2 contains something like :

.... 7
..... 2
....2
.....7

and what I want to be written in the new file i.e. nf is something like:

297 404 7
297 404 7
297 404 7
297 404 7
297 404 7
297 404 7
297 404 7
297 404 7
297 404 7
297 404 7
297 404 7
297 404 7
297 404 7
297 404 7
297 404 2
297 404 2
297 404 2
297 404 2
297 404 2

which m getting but partially correct because only last value is changing
not the first two... which should not happen.. In every loop all the three
values should change..
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130128/b5ff0de2/attachment.html>


More information about the Python-list mailing list