title: Redirecting the output of a python function from STDOUT to variable in Python
body: <p>This is what I am trying to achieve</p>
  
  <pre>
  <code>
  def fun():
      runner = InteractiveConsole()
      while(True):
          code = raw_input()
          code.rstrip('\n')
          # I want to achieve the following
          # By default the output and error of the 'code' is sent to STDOUT and STDERR
          # I want to obtain the output in two variables out and err
          out,err = runner.push(code)
  </code>
  </pre>
  
  <p>All the solution that I have looked at till now, use either pipes to issue separate script execution command (which is not possible in my case). Any other way I can achieve this?</p>