擅长:python、mysql、java
<p>文件有一个字节偏移量,每当您读或写文件时,它都会更新。这将实现您最初预期的效果:</p>
<pre><code>with open("file.txt") as f:
a = f.readlines()
f.seek(0) # seek to the beginning of the file
b = f.readline()
</code></pre>
<p>现在<code>a</code>是所有的行,<code>b</code>只是第一行。在</p>