How do I read two lines from a file at a time using python
<p>I am coding a python script that parses a text file. The format of this text file is such that each element in the file uses two lines and for convenience I would like to read both lines before parsing. Can this be done in python?</p>

<p>I would like to some something like:</p>

<pre><code>f = open(filename, "r")
for line in f:
    line1 = line
    line2 = f.readline()

f.close
</code></pre>

<p>But this breaks saying that </p>

<pre><code>ValueError: Mixing iteration and read methods would lose data
</code></pre>

<p>Does anyone have any ideas?</p>

<p>Greatful for any help,</p>

<p>/Daniel</p>

<h3>Related:</h3>

<ul>
<li><a href="http://stackoverflow.com/questions/434287/what-is-the-most-pythonic-way-to-iterate-over-a-list-in-chunks">What is the most “pythonic” way to iterate over a list in chunks?</a></li>
</ul>
