Possible Duplicate:
reading lines 2 at a time
In python we can iterate over file line by line. But what if i want iterate by two lines?
f = open("filename")
for line1, line2 in ?? f ??:
do_stuff(line1, line2)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could do something like this:
You may need to watch for a
StopIterationerror on the call tonext(fh)if you have odd lines. The solutions withizip_longestare probably better able to avoid that need.