擅长:python、mysql、java
<p>试试这个。它使用你提到的第三种方法,但不会生成新文件</p>
<pre><code>filePath = r"E:\try.txt"
file_str = ""
with open(filePath,'r') as f:
f.next() # skip header line
for line in f:
file_str = file_str + line
with open(filePath, "w") as f:
f.write(file_str)
</code></pre>