擅长:python、mysql、java
<p>如果要将doc2的文本复制到doc1,请使用:</p>
<pre><code>with open('doc2', 'r') as doc2:
read = doc2.readlines()
with open('doc1', 'w') as doc2: # Not 'r' (read), use 'w' (write)
doc1.writelines(read)
</code></pre>
<p>解释(如果不好,请道歉):</p>
<pre><code>open(file that you want to open, mode of opening)
# open the file with an specific mode, ('r' read, 'w' write, there are other like 'r+', 'w+', etc)
# you have to use open with a variable like:
file = open('doc1', 'r')
with open('doc1', 'r') as doc:
# you open the doc1 in the variable doc for a shot while, i mean, when you finish to use the file, it will automatly close.
read = doc2.readlines()
# you read the file (in this case 'doc2') (only can be done with reading modes [or readding and writting modes]) and load it in a variable ('read')
doc1.writelines(read)
# you write in the file ('doc1') all the text or values loaded in the variable ('read'), (you can only write in writting modes (or writting and readding)
</code></pre>
<p>我希望这对你有帮助,也为我的英语不好感到抱歉。你知道吗</p>