擅长:python、mysql、java
<p>给你</p>
<pre><code>text = open("textfile.txt").readlines()
counter = 0
for row in text:
counter += 1 # just snags the total amount of rows
newtext = open("textfile.txt","w")
newtext.write(f"line_count = {counter}\n\n") # This is your header xoxo
for row in text:
newtext.write(row) # put all of the original lines back
newtext.close()
</code></pre>
<p>确保您输入了文本文件的路径,但是这个简短的脚本只会固定在您想要的那一行\u count=Number头上。干杯</p>