Read STDIN as bytes rather than a string

Christian Heimes lists at cheimes.de
Mon Jun 18 19:35:31 EDT 2012


Am 19.06.2012 01:13, schrieb Jason Friedman:
> I tried this:

sys.stdin wraps a buffered reader which itself wraps a raw file reader.

>>> sys.stdin
<_io.TextIOWrapper name='<stdin>' mode='r' encoding='UTF-8'>
>>> sys.stdin.buffer
<_io.BufferedReader name='<stdin>'>
>>> sys.stdin.buffer.raw
<_io.FileIO name='<stdin>' mode='rb'>

You should read from sys.stdin.buffer unless you really need the bare
metal.

Christian




More information about the Python-list mailing list