python - How to iterate across lines in two files simultaneously? -


i have 2 files, , want perform line-wise operation across both of them. (in other words, first lines of each file correspond, second, etc.) now, can think of number of cumbersome ways iterate across both files simultaneously; however, python, imagine there syntactic shorthand.

in other words, there simple way adapt the

for line in file: 

so pulls data both files simultaneously?

use itertools.izip join 2 iterators.

from itertools import izip line_from_file_1, line_from_file_2 in izip(open(file_1), open(file_2)): 

if files of unequal length, use izip_longest.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -