title: How to set sys.stdout encoding in Python 3?
body: <p>Setting the default output encoding in Python 2 is a well-known idiom:</p>
  
  <pre><code>sys.stdout = codecs.getwriter("utf-8")(sys.stdout)
  </code></pre>
  
  <p>This wraps the <code>sys.stdout</code> object in a codec writer that encodes output in UTF-8.</p>
  
  <p>However, this technique does not work in Python 3 because <code>sys.stdout.write()</code> expects a <code>str</code>, but the result of encoding is <code>bytes</code>, and an error occurs when <code>codecs</code> tries to write the encoded bytes to the original <code>sys.stdout</code>.</p>
  
  <p>What is the correct way to do this in Python 3?</p>