title: Python3 compatability with file object
body: <p>I have a class/object that is a subprocess of a bunch of cmds in linux.  The object has something like:</p>
  <pre><code>def __enter__(self):
      self.proc = subprocess.Popen(self.cmd, bufsize=-1, shell=True, stdout=subprocess.PIPE, executable=&quot;/bin/bash&quot;)
      return self.process.stdout 
  </code></pre>
  <p>This basically return a <code>file</code> object in Python2 and an <code>_io.BufferedReader</code> for Python3.</p>
  <p>I perform a bunch of logic on each line and create a bunch of generators.  What is the best way to support both python 2 and 3.  For example if I have something like</p>
  <pre><code>line = input_file.next().strip().split(' ')
  </code></pre>
  <p>Works okay with Python 2, but for Python 3 I'll get something like</p>
  <pre><code>`_io.BufferedReader` object has no attribute 'next'
  </code></pre>
  <p>If I update <code>input_file.next()</code> to be <code>input_file.readline()</code> I would get an error of:</p>
  <pre><code>a bytes-like object is required, not 'str'
  </code></pre>
  <p>I can keep updating it accordingly to work for Python3, but is there a better way to do it without completely different algo/logic per each case?</p>