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

"Martin v. Löwis" martin at v.loewis.de
Thu Nov 16 18:31:06 EST 2006


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?

Regards,
Martin



More information about the Python-list mailing list