擅长:python、mysql、java
<p>不需要在python中检查EOF,只需执行以下操作:</p>
<pre><code>with open('t.ini') as f:
for line in f:
print line
if 'str' in line:
break
</code></pre>
<p><a href="http://docs.python.org/2/tutorial/inputoutput.html#methods-of-file-objects">Why the ^{<cd1>} statement</a>:</p>
<blockquote>
<p>It is good practice to use the <code>with</code> keyword when dealing with file
objects. This has the advantage that the file is properly closed after
its suite finishes, even if an exception is raised on the way.</p>
</blockquote>