擅长:python、mysql、java
<p>有一个<code>fobj</code>(在第二个别名中)的拼写错误。你知道吗</p>
<pre><code>with open('aaa.txt') as readable, open('bbb.txt', 'w+') as writeable:
... for line in readable:
... writeable.write("\item %s" % line.strip())
</code></pre>
<p>打开文件进行读取时,除非重写,否则将采用<code>'r'</code>读取模式。<a href="https://docs.python.org/2/library/functions.html#open" rel="nofollow">https://docs.python.org/2/library/functions.html#open</a></p>
<p>另外,您不需要使用<code>.writelines</code>而是<code>.write</code>,因为您所写的只是一个字符串。<a href="https://docs.python.org/2/library/stdtypes.html?highlight=writelines#file-objects" rel="nofollow">https://docs.python.org/2/library/stdtypes.html?highlight=writelines#file-objects</a></p>