擅长:python、mysql、java
<p>给定原始字节字符串,可以通过解码将其转换为<code>unicode</code>对象(Python 2.x)或<code>str</code>对象(Python 3.x):</p>
<pre><code>for name in ops.listdir(somedir.decode("utf-8")):
</code></pre>
<p>使用字节字符串编码的任何编码,而不是<code>"utf-8"</code>。如果省略编码,将使用Python的标准编码(2.x中的<code>ascii</code>,3.x中的<code>utf-8</code>)。</p>
<p>有关详细信息,请参见<a href="http://docs.python.org/howto/unicode.html" rel="noreferrer">Unicode HOWTO</a>(<a href="http://docs.python.org/py3k/howto/unicode.html" rel="noreferrer">3.x</a>)。</p>