How do I obtain the filenames' encoding after os.listdir?
Martin v. Löwis
martin at v.loewis.de
Wed Jun 4 14:53:38 EDT 2003
Grzegorz Adam Hankiewicz <gradha at titanium.sabren.com> writes:
> I want to transform the strings to unicode objects so I can use them
> with pygtk, and the current process works ok for my machine. The
> question is how do I know the encoding of the filenames? Currently
> I'm presuming latin1, but if somebody else uses a different encoding,
> how do I know which one?
The convention is that all file names are in the locale's encoding,
which is exposed as locale.nl_langinfo(locale.CODESET) (after
setlocale has been invoked).
> The documentation says string.decode can use as parameter "ignore"
> or "replace", but using them only raises LookupErrors.
You still need to provide an encoding. The error arguments is the
*second* argument to decode.
Regards,
Martin
More information about the Python-list
mailing list