擅长:python、mysql、java
<p>这应该简单到:</p>
<pre><code>with open('somefile.txt', 'a') as the_file:
the_file.write('Hello\n')
</code></pre>
<p>从文档中:</p>
<blockquote>
<p>Do not use <code>os.linesep</code> as a line terminator when writing files opened in text mode (the default); use a single '\n' instead, on all platforms.</p>
</blockquote>
<p>一些有用的阅读:</p>
<ul>
<li><a href="http://docs.python.org/reference/compound_stmts.html#the-with-statement" rel="noreferrer">The ^{<cd1>} statement</a></li>
<li><a href="http://docs.python.org/library/functions.html?highlight=open#open" rel="noreferrer">^{<cd2>}</a>
<ul>
<li>“a”用于追加或使用</li>
<li>“w”以截断方式写入</li>
</ul></li>
<li><a href="http://docs.python.org/library/os.html" rel="noreferrer">^{<cd3>}</a>(特别是<a href="http://docs.python.org/library/os.html?highlight=os.linesep#os.linesep" rel="noreferrer">^{<cd4>}</a>)</li>
</ul>