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

Jean-Paul Calderone exarkun at divmod.com
Thu Nov 16 19:01:48 EST 2006


On Fri, 17 Nov 2006 00:31:06 +0100, "\"Martin v. Löwis\"" <martin at v.loewis.de> wrote:
>gabor schrieb:
>>> All this code will typically work just fine with the current behavior,
>>> so people typically don't see any problem.
>>>
>>
>> i am sorry, but it will not work. actually this is exactly what i did,
>> and it did not work. it dies in the os.path.join call, where file_name
>> is converted into unicode. and python uses 'ascii' as the charset in
>> such cases. but, because listdir already failed to decode the file_name
>> with the filesystem-encoding, it usually also fails when tried with
>> 'ascii'.
>
>Ah, right. So yes, it will typically fail immediately - just as you
>wanted it to do, anyway; the advantage with this failure is that you
>can also find out what specific file name is causing the problem
>(whereas when listdir failed completely, you could not easily find
> out the cause of the failure).
>
>How would you propose listdir should behave?

Umm, just a wild guess, but how about raising an exception which includes
the name of the file which could not be decoded?

Jean-Paul



More information about the Python-list mailing list