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

Chris Angelico rosuav at gmail.com
Mon Jan 28 09:49:32 EST 2013


On Tue, Jan 29, 2013 at 1:37 AM, Dave Angel <d at davea.name> wrote:
> What you want is the zip() function
>
> for l,s in zip(f1, f2):
>     #you now have one line from each file,
>     #   which you can then validate and process
>
> Note, this assumes that when a line is "bad" from either file, you're going
> to also ignore the corresponding line from the other.  If you have to
> accommodate variable misses in the lining up, then your work is *much*
> harder.

Much harder? Not really - see my solution above with a simple 'break'.
Much less clear what's going on, though, it is. Iterating together
over both files with zip is much cleaner.

ChrisA



More information about the Python-list mailing list