How to Redirect Python Stderr to String While Still Displaying
<p>I'm capturing the stderr of my script to I can later save to a database via:</p>

<pre><code>ostderr = sys.stderr
sys.stderr = StringIO()

# do stuff

mymodel.errors = sys.stderr.getvalue()
mymodel.save()
print mymodel.errors
sys.stderr = ostderr
</code></pre>

<p>Unfortunately, this makes casual debugging more difficult because if any errors occur, I won't see them until the script terminates.</p>

<p>How do I capture stderr in a string, as I'm doing above, but still display it in realtime to the console?</p>
