title: Python 2.7 io.open: Use "from io import open" or "io.open()"?
body: <p>I’m working on some code that should run under both Python 2.7.x <em>and</em> Python 3.3+ unchanged, and uses Unicode data text file I/O.</p>
  
  <p>So which is better—<strong>and why?</strong></p>
  
  <p><strong>Variant 1:</strong></p>
  
  <pre><code>import io
  encoding = 'utf-8'
  
  with io.open('Unicode.txt', 'w', encoding=encoding) as f:
      …
  with io.open('Unicode.txt', 'r', encoding=encoding) as f:
      …
  </code></pre>
  
  <p><strong>Variant 2:</strong></p>
  
  <pre><code>from io import open
  encoding = 'utf-8'
  
  with open('Unicode.txt', 'w', encoding=encoding) as f:
      …
  with open('Unicode.txt', 'r', encoding=encoding) as f:
      …
  </code></pre>
  
  <p>Personally, I’d <em>tend</em> to use Variant 2, because the code should be as Python-3-<em>ish</em> as possible, just providing backport stubs for Python 2.7.x. It also looks cleaner and I wouldn’t have to change existing code much. Also I think maybe I could save a little by not importing the whole io module.</p>