I want to redirect the stdout
to a file. But This will affect the raw_input
. I need to redirect the output of raw_input
to stderr
instead of stdout
. How can I do that?
Redirect stdout
to stderr
temporarily, then restore.
import sys
old_raw_input = raw_input
def raw_input(*args):
old_stdout = sys.stdout
try:
sys.stdout = sys.stderr
return old_raw_input(*args)
finally:
sys.stdout = old_stdout
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments