Skip to content

Instantly share code, notes, and snippets.

@cjhanks
Created August 9, 2012 17:50
Show Gist options
  • Save cjhanks/3306452 to your computer and use it in GitHub Desktop.
Save cjhanks/3306452 to your computer and use it in GitHub Desktop.
sys imports & redirection
#!/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