assign output of help to a variable instead of stdout in python
<p>I want to do something like this in the python interpreter.</p>

<pre><code>myhelp = help(myclass)
</code></pre>

<p>but the output goes to stdout.  Is it possible to assign it to a variable?</p>

<p>Thanks!</p>

<p>You can capture stdout while <code>help(myclass)</code> runs:</p>

<pre><code>from cStringIO import StringIO
import sys

stdout = sys.stdout
buffer = StringIO()
sys.stdout = buffer

help(myclass)

sys.stdout = stdout

myhelp = buffer.getvalue()
</code></pre>

python