os.lisdir, gets unicode, returns unicode... USUALLY?!?!?
gabor
gabor at nekomancer.net
Fri Nov 17 05:35:47 EST 2006
Fredrik Lundh wrote:
> gabor wrote:
>
>> get an Unicode-exception, as everywhere else. you see, exceptions are
>> ok, i can deal with them.
>
>> p.s: one additional note. if you code expects os.listdir to return
>> unicode, that usually means that all your code uses unicode strings.
>> which in turn means, that those filenames will somehow later interact
>> with unicode strings. which means that that byte-string-filename will
>> probably get auto-converted to unicode at a later point, and that
>> auto-conversion will VERY probably fail
>
> it will raise an exception, most likely. didn't you just say that
> exceptions were ok?
yes, but it's raised at the wrong place imho :)
(just to clarify: simply pointing out this behavior in the documentation
is also one of the possible solutions)
for me the current behavior seems as if file-reading would work like this:
a = open('foo.txt')
data = a.read()
a.close()
print data
>>> TheFileFromWhichYouHaveReadDidNotExistException
gabor
More information about the Python-list
mailing list