Python 3 encoding question: Read a filename from stdin, subsequently open that filename

Dan Stromberg drsalists at gmail.com
Tue Nov 30 19:51:44 EST 2010


On Tue, Nov 30, 2010 at 11:47 AM, Martin v. Loewis <martin at v.loewis.de> wrote:
>> Does anyone know what I need to do to read filenames from stdin with
>> Python 3.1 and subsequently open them, when some of those filenames
>> include characters with their high bit set?
>
> If your files on disk use file names encoded in iso-8859-1, don't set
> your locale to a UTF-8 locale (as you apparently do), but set it to
> a locale that actually matches the encoding that you use.
>
> Regards,
> Martin
>

It'd be great if all programs used the same encoding on a given OS,
but at least on Linux, I believe historically filenames have been
created with different encodings.  IOW, if I pick one encoding and go
with it, filenames written in some other encoding are likely to cause
problems.  So I need something for which a filename is just a blob
that shouldn't be monkeyed with.



More information about the Python-list mailing list