i want to read bytes. sys.stdin is opened in textmode, yet it has a buffer that can be used to read bytes: sys.stdin.buffer.
sys.stdin
sys.stdin.buffer
my problem is
Try this:
import sys ssb = sys.stdin.buffer.read(1) if ssb == b'h': print(ssb+sys.stdin.buffer.read())
Echo a string:
a@fuhq:~$ echo 'hi' | python3 buf_test.py b'hi\n'
Redirect a file:
a@fuhq:~$ cat hi.text hi a@fuhq:~$ python3 buf_test.py < hi.text b'hi\n'