title: Custom print function yield from sub function
body: <p>I customized the print function to print to console and also send print lines to an object so I can pipe them to a gui using a yield function.  This works fine, until my function calls a sub function and that sub function prints to console.  If I import my custom print into that subfunction, it doesn't work because that print is yielding results to the subfunction, not the original outerfunction.</p>
  
  <p>Is there a way to yield result from my custom print directly back to the main function and skip this inceptionesque nightmare?  </p>
  
  <pre><code>from __future__ import print_function
  import __builtin__
  
  def print(*args, **kwargs):
      import builtins
      import io
      from contextlib import redirect_stdout
      builtins.print(*args, **kwargs)
      with io.StringIO() as buf, redirect_stdout(buf):
          builtins.print(*args, **kwargs)
          output = buf.getvalue()
      return output
  </code></pre>