LC_ALL and os.listdir()

Serge Orlov Serge.Orlov at gmail.com
Wed Feb 23 16:42:43 EST 2005


"Martin v. Löwis" wrote:
>> My goal is to build generalized code that consistently works with all
>> kinds of filenames.
>
> Then it is best to drop the notion that file names are
> character strings (because some file names aren't). You
> do so by converting your path variable into a byte
> string. To do that, you could try
>
> path = path.encode(sys.getfilesystemencoding())

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.

  Serge.





More information about the Python-list mailing list