[Python-ideas] Py3 unicode impositions

Simon Sapin simon.sapin at kozea.fr
Wed Feb 15 14:41:46 CET 2012

Le 14/02/2012 22:08, Paul Moore a écrit :
> Thinking about how I'd code something like "cat" naively in C (while
> ((i = getchar()) != EOF) { putchar(i); }), I guess encoding=latin1 is
> the way for Python to "work like everything else" in this context.


The Python equivalent to your C program is to use bytes without decoding 
at all: open a file with 'rb' mode, use sys.stdin.buffer, ...

I think this is the right thing to do if you want to pass through 
unmodified text without knowing the encoding.

Simon Sapin

More information about the Python-ideas mailing list