<p>我已经编写了一个Python程序来遍历目录中的文本文件,并用添加的行号创建每个文件的新版本。以下是程序中的相关功能:</p>
<pre><code>def create_lined_ver(filename):
new_text = []
with open(filename + ".txt", "r+") as f:
text = f.readlines()
for (num, line) in enumerate(text):
new_text.append("[{0}]: ".format(num) + line)
with open(filename + "_lined" + ".txt", "a+") as f:
for line in new_text:
f.write(line)
</code></pre>
<p>为了测试它,我在一批文本文件上运行它,然后出于好奇,再次运行它(在已经编号的文件中添加第二组行号)。我注意到,每次运行程序时,新创建的文件的文件大小都比每行添加5-6个字符时的大小要大得多。文件大小从150KB(原始)跳到7001800,然后每次运行3000kB。你知道吗</p>
<p>是什么导致文件大小增加这么多?你知道吗</p>