擅长:python、mysql、java
<p>1)先打开输入文件,然后打开输出文件。这样,如果输入文件不存在,您就可以报告该错误,而不必首先创建(现在没有用的)输出文件。你知道吗</p>
<p>2)迭代输入文件(正如您所做的),而不是调用<code>file.read()</code>或<code>file.readlines()</code>。调用其中一个函数可以使用基本上无限量的内存。你知道吗</p>
<p>3)在给定的特定情况下,使用<a href="https://docs.python.org/2/library/shutil.html#shutil.copyfileobj" rel="nofollow">^{<cd3>}</a>或<a href="https://docs.python.org/2/library/shutil.html#shutil.copyfile" rel="nofollow">^{<cd4>}</a>。你知道吗</p>