擅长:python、mysql、java
<pre><code>u'\uf04a'
</code></pre>
<p>已经<em>是一个Unicode对象,这意味着不需要解码。如果您的目标是UTF-8这样的特定文件编码(UTF-8与Unicode不同,但总是与Unicode混淆),那么您只能对其进行编码<em>编码</em>。在</p>
^{pr2}$
<p>提供一个字符串(python2)或<code>bytes</code>对象(python3),然后可以将其写入文件或UTF-8终端等</p>
<p>因为cp1252没有这个字符,所以不能将它编码为普通的Windows字符串。在</p>
<p>你可以通过告诉编码器用<code>?</code>替换丢失的字符,把它转换成一种不包含那些有问题字符的编码:</p>
<pre><code>>>> u'who\uf04a why\uf04c'.encode("ascii", errors="replace")
'who? why?'
</code></pre>