title: Python 3: write binary to stdout respecting buffering
body: <p>There is an existing question <a href="https://stackoverflow.com/questions/908331/how-to-write-binary-data-to-stdout-in-python-3">How to write binary data to stdout in python 3?</a> but all of the answers suggest <code>sys.stdout.buffer</code> or variants thereof (e.g., manually rewrapping the file descriptor), which have a problem: they don't respect buffering:</p>
  
  <pre><code>MacBook-Pro-116:~ ezyang$ cat test.py
  import sys
  sys.stdout.write("A")
  sys.stdout.buffer.write(b"B")
  MacBook-Pro-116:~ ezyang$ python3 test.py | cat
  BA
  </code></pre>
  
  <p>Is there a way to write binary data to stdout while respecting buffering with respect to <code>sys.stdout</code> and unadorned <code>print</code> statements? (The actual use-case is, I have "text-like" data of an unknown encoding and I just want to pass it straight to stdout without making a commitment to a particular encoding.)</p>