Manajer konteks untuk mengalihkan sementara sys.stdout ke file lain atau objek mirip file.
contextlib.redirect_stdout(new_target)
with redirect_stdout(io.StringIO()) as f:
help(pow)
s = f.getvalue()
with open('help.txt', 'w') as f:
with redirect_stdout(f):
help(pow)
with redirect_stdout(sys.stderr):
help(pow)