Info
Content

Capture stdout

Sometimes, it's required to capture the stdout from a function or module import. This is natively possible in Python using contextlib and io.

from contextlib import redirect_stdout
import io

f = io.StringIO()
with redirect_stdout(f):
    help(func)
s = f.getvalue()
No Comments
Back to top