Re: Read STDIN as bytes rather than a string

2012-06-19 Thread Oscar Benjamin
On 19 June 2012 00:53, Jason Friedman ja...@powerpull.net wrote: Which leads me to another question ... how can I debug these things? $ echo 'hello' | python3 -m pdb ~/my-input.py /home/jason/my-input.py(2)module() - import sys (Pdb) *** NameError: name 'hello' is not defined --

Read STDIN as bytes rather than a string

2012-06-18 Thread Jason Friedman
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:

Re: Read STDIN as bytes rather than a string

2012-06-18 Thread Benjamin Kaplan
On Mon, Jun 18, 2012 at 4:13 PM, Jason Friedman ja...@powerpull.net wrote: 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

Re: Read STDIN as bytes rather than a string

2012-06-18 Thread Christian Heimes
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'

Re: Read STDIN as bytes rather than a string

2012-06-18 Thread Jason Friedman
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

Re: Read STDIN as bytes rather than a string

2012-06-18 Thread Jason Friedman
Which leads me to another question ... how can I debug these things? $ echo 'hello' | python3 -m pdb ~/my-input.py /home/jason/my-input.py(2)module() - import sys (Pdb) *** NameError: name 'hello' is not defined -- http://mail.python.org/mailman/listinfo/python-list