"convert" string to bytes without changing data (encoding)

Chris Angelico rosuav at gmail.com
Fri Mar 30 15:10:03 EDT 2012


On Sat, Mar 31, 2012 at 6:06 AM, Serhiy Storchaka <storchaka at gmail.com> wrote:
> 28.03.12 21:13, Heiko Wundram написав(ла):
>
>> Reading from stdin/a file gets you bytes, and
>> not a string, because Python cannot automagically guess what format the
>> input is in.
>
>
> In Python3 reading from stdin gets you string. Use sys.stdin.buffer.raw for
> access to byte stream. And reading from file opened in text mode gets you
> string too.

True. But that's only if it's been told the encoding of stdin (which I
believe is the normal case on Linux). It's still not "automagically
guess(ing)", it's explicitly told.

ChrisA



More information about the Python-list mailing list