[Tutor] Nested loop of I/O tasks
Kent Johnson
kent37 at tds.net
Wed Nov 25 12:33:21 CET 2009
On Wed, Nov 25, 2009 at 1:38 AM, Christian Witts <cwitts at compuscan.co.za> wrote:
> If your output is going to be sorted like that so you know NONAME will be on
> the same line in both files what you can do is
>
> INCT = open('something.csv', 'r')
> INMRI = open('something_else.csv', 'r')
>
> rec_INCT = INCT.readline()
> rec_INMRI = INMRI.readline()
>
> while rec_INCT and rec_INMRI:
> name, x, y, z, a, b, c, d = rec_INCT.split(',')
> NAME, X, Y, Z, A, B, C, D = rec.INMRI.split(',')
>
> if name == NAME:
> print 'Matches'
>
> rec_INCT = INCT.readline()
> rec_INMRI = INMRI.readline()
>
> INCT.close()
> INMRI.close()
For this to work the files must have the same names in the same order.
It's not enough that they be sorted, they have to have the same
entries.
Kent
More information about the Tutor
mailing list