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

Dan Stromberg drsalists at gmail.com
Tue Nov 30 20:03:14 EST 2010


On Tue, Nov 30, 2010 at 9:53 AM, Peter Otten <__peter__ at web.de> wrote:
> $ ls
> $ python3
> Python 3.1.1+ (r311:74480, Nov  2 2009, 15:45:00)
> [GCC 4.4.1] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> with open(b"\xe4\xf6\xfc.txt", "w") as f:
> ...     f.write("hello\n")
> ...
> 6
>>>>
> $ ls
> ???.txt

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".



More information about the Python-list mailing list