擅长:python、mysql、java
<p>可以将字节字符串转换为Unicode,但如果它包含任何非ASCII字符,则必须指定编码。在</p>
<pre><code>if y.decode('iso-8859-1') == x:
print(u'{0!r} converted to Unicode == {1}".format(y, x))
</code></pre>
<p>对于给定的示例,这是不正确的;但可能<code>y</code>使用了不同的编码。在</p>
<p>从理论上讲,您可以采用任何一种方式进行转换,但通常情况下,在内部使用所有Unicode,并将其他编码转换为Unicode以便在您的代码中使用(而不是相反)。在</p>