擅长:python、mysql、java
<p>假设可以将全文加载到内存中,则可以打开文件,按行拆分,并为每行附加“35;”。然后保存:-):</p>
<pre><code>with open(filepath, 'r') as f: # load file
lines = f.read().splitlines() # read lines
with open('new_file.txt', 'w') as f:
f.write('\n'.join([line + '#' for line in lines])) # write lines with '#' appended
</code></pre>