I'd like to be able to read binary data from stdin with python.
However, when I use input = sys.stdin.buffer.read(), I get the error that AttributeError: 'file' object has no attribute 'buffer'. This seems strange because the docs say that I should be able to use the underlying buffer object - how can I fix / work around this?
Notes: I've checked out the last time this was asked, but the answers there are all either "use -u", "use buffer" (which I'm trying), or something about reading from files. The first and last don't help because I have no control over the users of this program (so I can't tell them to use particular arguments) and because this is stdin - not files.
sys.stdin.read(). It's already a binary stream.sys.stdin = os.fdopen(sys.stdin.fileno(), 'rb', 0)raw_input? Have I just not slept enough?-uwould still be needed to read it in unbuffered & binary mode. If the OP's expecting to read unbuffered (i.e. no waiting for the newline) from the keyboard though (e.g. writing a game), they'll probably also need to enable "raw" mode on the tty