Skip to content

Instantly share code, notes, and snippets.

@djsmith42
Created October 25, 2012 23:44
Show Gist options
  • Save djsmith42/3956189 to your computer and use it in GitHub Desktop.
Save djsmith42/3956189 to your computer and use it in GitHub Desktop.
from contextlib import contextmanager
import sys, os
@contextmanager
def suppress_stdout():
with open(os.devnull, "w") as devnull:
old_stdout = sys.stdout
sys.stdout = devnull
try:
yield
finally:
sys.stdout = old_stdout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment