[Python-Dev] Filename as byte string in python 2.6 or 3.0?

Guido van Rossum guido at python.org
Tue Sep 30 20:16:31 CEST 2008


On Tue, Sep 30, 2008 at 11:12 AM,  <glyph at divmod.com> wrote:

> The one thing it doesn't do is expose the decoding rules for the higher-
> level applications to deal with.  I am pretty sure I don't understand how
> the interaction between filesystem encoding and user locale works in that
> case, though, so I can't immediately recommend a way to do it.

You can ask what the filesystem encoding is with
sys.getfilesystemencoding(). On my Linux box I can make this return
anything I like by setting LC_CTYPE=en_US.<whatever> (as long as
<whatever> is a recognized encoding). There are probably 5 other
environment variables to influence this. :-(

Of course that doesn't help for undecodable filenames, and in that
case I don't think *anything* can help you unless you have a lot of
additional knowledge about what the user might be doing, e.g. you know
a few other encodings to try that make sense for their environment.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list