I\'m using python\'s ftplib to write a small FTP client, but some of the functions in the package don\'t return string output, but print to stdout.
ftplib
stdout
There is contextlib.redirect_stdout() function in Python 3.4:
import io from contextlib import redirect_stdout with io.StringIO() as buf, redirect_stdout(buf): print('redirected') output = buf.getvalue()
Here's code example that shows how to implement it on older Python versions.