LC_ALL and os.listdir()

Serge Orlov Serge.Orlov at gmail.com
Thu Feb 24 07:05:25 EST 2005


Duncan Booth wrote:
> Martin v. Löwis wrote:
>
> > Serge Orlov wrote:
> >> Shouldn't os.path.join do that? If you pass a unicode string
> >> and a byte string it currently tries to convert bytes to
> >> characters
> >> but it makes more sense to convert the unicode string to bytes
> >> and return two byte strings concatenated.
> >
> > Sounds reasonable. OTOH, this would be the only (one of a very
> > few?) occasion where Python combines byte+unicode => byte.
> > Furthermore, it might be that the conversion of the Unicode
> > string to a file name fails as well.
> >
> > That said, I still think it is a good idea, so contributions
> > are welcome.
> >
> It would probably mess up those systems where filenames really are
> unicode strings and not byte sequences.
>
> Windows (when using NTFS) stores all the filenames in unicode, and
> Python uses the unicode api to implement listdir (when given a
> unicode path). This means that the filename never gets encoded to
> a byte string either by the OS or Python. If you use a byte string
> path than the filename gets encoded by Windows and Python just
> returns what it is given.

Sorry for being not clear, but I meant posixpath.join since the whole
discussion is about posix systems.

  Serge.




More information about the Python-list mailing list