import sys s = b'String of bytes \xab\xcd\xef\xff' # print(s) : b'String of bytes \xab\xcd\xef\xff' sys.stdout.buffer.write(s)