I'd like to be able to read binary data from stdin and have it preserved as binary data (i.e. no coercion to string as sys.stdin.read does). How can I do this with Python 2.7?
Edit: The answers given here, are not suitable for the following reasons:
- Using the extension "-u" will not work because I have no control over how users interact with the program.
- Using sys.stdin.read will not work because that function coerces the input to a string - I would like for it to remain as bytes.
- Using "msvcrt.setmode (sys.stdin.fileno(), os.O_BINARY)" will not work because that is a windows-specific solution and I'd like this to be cross-platform.