擅长:python、mysql、java
<p>这里有一些来自<a href="http://docs.python.org/library/sys.html#sys.getfilesystemencoding" rel="nofollow">documentation</a>的有趣的东西:</p>
<blockquote>
<p>sys.getfilesystemencoding()</p>
<p>Return the name of the encoding used
to convert Unicode filenames into
system file names, or None if the
system default encoding is used. The
result value depends on the operating
system: On Mac OS X, the encoding is
'utf-8'. On Unix, the encoding is the
user’s preference according to the
result of nl_langinfo(CODESET), or
None if the nl_langinfo(CODESET)
failed. On Windows NT+, file names are
Unicode natively, so no conversion is
performed. getfilesystemencoding()
still returns 'mbcs', as this is the
encoding that applications should use
when they explicitly want to convert
Unicode strings to byte strings that
are equivalent when used as file
names. On Windows 9x, the encoding is
'mbcs'.</p>
<p>New in version 2.3.</p>
</blockquote>
<p>如果我理解正确,则应将文件名传递为unicode:</p>
<pre><code>f = open(unicode(path, encoding))
</code></pre>