擅长:python、mysql、java
<p>您需要使用readlines来获取所有行的列表:</p>
<p><code>open(path).readlines() # readlines</code></p>
<p><code>readline()</code>读取一行。在</p>
<p>也可以在每一行上迭代:</p>
<pre><code>with open(path) as f: # with closes your files
for line in f:
print(line)
</code></pre>
<p>迭代每一行,您应该得到:</p>
^{pr2}$
<p>您必须添加一个空行作为文件的开头,否则您至少会得到第一行。在</p>