擅长:python、mysql、java
<p>将<code>glob</code>与包含Unicode字符的文件名一起使用时,请为模式使用Unicode字符串。这使得<code>glob</code>返回Unicode字符串而不是字节字符串。输出时,打印Unicode字符串会自动在控制台的编码中对它们进行编码。如果您的歌曲包含主机编码不支持的字符,您仍然会遇到问题。在这种情况下,将数据写入UTF-8编码的文件,并在支持UTF-8的编辑器中查看。在</p>
<pre><code>>>> import glob
>>> for f in glob.glob('*'): print f
...
ThriftworksFaderThriftworks - Fader - 01 180░.flac
>>> for f in glob.glob(u'*'): print f
...
ThriftworksFaderThriftworks - Fader - 01 180°.flac
</code></pre>
<p>这也适用于<code>os.walk</code>,是进行递归搜索的一种更简单的方法:</p>
^{pr2}$
<p>输出:</p>
^{3}$