Read STDIN as bytes rather than a string

Jason Friedman jason at powerpull.net
Mon Jun 18 19:13:40 EDT 2012


I tried this:

Python 3.2.2 (default, Feb 24 2012, 20:07:04)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> import io
>>> fh = io.open(sys.stdin)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: invalid file: <_io.TextIOWrapper name='<stdin>' mode='r'
encoding='UTF-8'>
>>> fh = io.open(sys.stdin, "rb")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: invalid file: <_io.TextIOWrapper name='<stdin>' mode='r'
encoding='UTF-8'>



More information about the Python-list mailing list