[Python-Dev] Unicode strings as filenames

Martin v. Loewis martin@v.loewis.de
Fri, 4 Jan 2002 20:27:59 +0100


> Would it be safe to set site.encoding to utf8 on Mac OS X by default? 

As MAL explains, no. Instead, you should extend the fragment

#if defined(MS_WIN32) && defined(HAVE_USABLE_WCHAR_T)
const char *Py_FileSystemDefaultEncoding = "mbcs";
#else
const char *Py_FileSystemDefaultEncoding = NULL; /* use default */
#endif

to cover OSX as well, setting the string to "utf-8". Then, Unicode
objects will be auto-converted to UTF-8 in open() and all posixmodule
calls; not sure whether OSX uses posixmodule, though...

Once you've done this, you should use es# specifiers with
Py_FileSystemDefaultEncoding wherever you retrieve a file or path
name from the application.

Returning file names to the user is a different story, though: it may
or may not be sensible to apply the file system encoding (if set)
whenever file names are returned to the application (mostly in
listdir).

HTH,
Martin