Read stdin as binary [duplicate] Read stdin as binary [duplicate] python python

Read stdin as binary [duplicate]


In Python 3, if you want to read binary data from stdin, you need to use its buffer attribute:

import sysdata = sys.stdin.buffer.read()

On Python 2, sys.stdin.read() already returns a byte string; there is no need to use buffer.