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

Chris Angelico rosuav at gmail.com
Mon Jan 28 09:19:23 EST 2013


On Tue, Jan 29, 2013 at 1:12 AM, inshu chauhan <insideshoes at gmail.com> wrote:
> 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 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..

In that case, Dave's suggestion to read into a list and iterate over
the list is to be strongly considered. But I'm not entirely sure what
your goal is here. Are you trying to make the Cartesian product of the
two files, where you have one line in the output for each possible
pair of matching lines? That is, for each line in the first file, you
make a line in the output for each line in the second? That's what
your code will currently do.

ChrisA



More information about the Python-list mailing list