title: Backporting Python 3 open(encoding="utf-8") to Python 2
body: <p>I have a Python codebase, built for Python 3, which uses Python 3 style open() with encoding parameter:</p>
  
  <p><a href="https://github.com/miohtama/vvv/blob/master/vvv/textlineplugin.py#L47" rel="noreferrer">https://github.com/miohtama/vvv/blob/master/vvv/textlineplugin.py#L47</a></p>
  
  <pre><code>    with open(fname, "rt", encoding="utf-8") as f:
  </code></pre>
  
  <p>Now I'd like to backport this code to Python 2.x, so that I would have a codebase which works with Python 2 and Python 3.</p>
  
  <p>What's the recommended strategy to work around <code>open()</code> differences and lack of encoding parameter?</p>
  
  <p>Could I have a Python 3 <code>open()</code> style file handler which streams bytestrings, so it would act like Python 2 <code>open()</code>?</p>