2012/7/17 And Clover <and-dev@doxdesk.com>:
But should we be encouraging their use on Windows? I would have thought it the best thing to stick with the Unicode string for paths on NT, so that the native Win32 Unicode APIs are used instead of the ANSI-code-page-bound C stdio. Encoding down to the fsencoding for Windows just means that any path including a character that isn't in the ANSI CP will fail.
os.fsencode() should not be used explicitly on Windows.
In lieu of some kind of abstract filepath object thatcould represent either bytes or str (depending on platform), how about a function that takes a str and only encodes it to bytes if the platform requires it?
You can use the str (Unicode) type on all platforms with Python 3, so use os.fsdecode(). os.listdir(str) does return str filenames on any platform for example. Victor