os.lisdir, gets unicode, returns unicode... USUALLY?!?!?

Johan von Boisman do-not-reply at by-mail.com
Fri Nov 17 05:12:41 EST 2006


Laurent Pointal wrote:
> gabor a écrit :
>> hi,
>>
>> from the documentation (http://docs.python.org/lib/os-file-dir.html) for
>> os.listdir:
>>
>> "On Windows NT/2k/XP and Unix, if path is a Unicode object, the result
>> will be a list of Unicode objects."
> 
> Maybe, for each filename, you can test if it is an unicode string, and
> if not, convert it to unicode using the encoding indicated by
> sys.getfilesystemencoding().
> 
> Have a try.
> 
> A+
> 
> Laurent.

Strange coincident, as I was wrestling with this problem only yesterday.

I found this most illuminating discussion on the topic with 
contributions from Mr Lövis and others:

http://www.thescripts.com/forum/thread41954.html

/johan



More information about the Python-list mailing list