title: How to capture stdout output from a Python function call?
body: <p>I'm using a Python library that does something to an object</p>
  <pre class="lang-py prettyprint-override"><code>do_something(my_object)
  </code></pre>
  <p>and changes it. While doing so, it prints some statistics to stdout, and I'd like to get a grip on this information. The proper solution would be to change <code>do_something()</code> to return the relevant information,</p>
  <pre class="lang-py prettyprint-override"><code>out = do_something(my_object)
  </code></pre>
  <p>but it will be a while before the devs of <code>do_something()</code> get to this issue. As a workaround, I thought about parsing whatever <code>do_something()</code> writes to stdout.</p>
  <p>How can I capture stdout output between two points in the code, e.g.,</p>
  <pre class="lang-py prettyprint-override"><code>start_capturing()
  do_something(my_object)
  out = end_capturing()
  </code></pre>
  <p>?</p>