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

Martin v. Loewis martin at v.loewis.de
Wed Dec 1 02:33:23 EST 2010


> This sounds like a strong prospect for how to get things working (I
> didn't realize open would accept a bytes argument for the filename),
> but I'm also interested in whether reading filenames from stdin and
> subsequently opening them is supposed to "just work" given a suitable
> encoding - like with Java which also uses unicode strings.  In Java,
> I'm told that ISO-8859-1 is supposed to "guarantee a roundtrip
> conversion".

It's the same in Python. However, as in Java, Python will *not*
necessarily use ISO-8859-1 when you pass a (Unicode) string to
open; instead, it will (as will Java) use your locale's encoding.

Regards,
Martin



More information about the Python-list mailing list