Created
August 9, 2012 17:50
-
-
Save cjhanks/3306452 to your computer and use it in GitHub Desktop.
sys imports & redirection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# DOES NOT WORK -------------------------------------------------------------- # | |
def does_not_work(): | |
from sys import stderr, stdout | |
_stdout = stdout | |
stdout = stderr | |
print('does_not_work()') | |
# DOES WORK ------------------------------------------------------------------ # | |
def does_work(): | |
import sys | |
_stdout = sys.stdout | |
sys.stdout = sys.stderr | |
print('does_work()') | |
does_not_work() | |
does_work() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment