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

gabor gabor at nekomancer.net
Fri Nov 17 05:26:51 EST 2006


Laurent Pointal wrote:
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.

> 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().
> 
i don't think it would work. because os.listdir already tried, and 
failed (that's why we got a byte-string and not an unicode-string)

gabor



More information about the Python-list mailing list