擅长:python、mysql、java
<p>错误不是来自Pycharm。在</p>
<p>来自Python文档:</p>
<blockquote>
<p>buffering is an optional integer used to set the buffering policy.
Pass 0 to switch buffering off <strong>(only allowed in binary mode)</strong></p>
</blockquote>
<p>您的代码只能在python2中工作,而不能在python3中工作。因为在python3中,<strong>字符串</strong>是Unicode代码点的不可变序列。你需要这里有字节。要在python3中实现这一点,您可以在无缓冲模式下将unicode <code>str</code>转换为<code>bytes</code>。在</p>
<p>例如:</p>
<pre><code>my_file.write("Testing unbuffered writing\n".encode("utf-8"))
</code></pre>