Skip to content

Instantly share code, notes, and snippets.

@jledet
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jledet/a575171a72f0f1db8797 to your computer and use it in GitHub Desktop.
Save jledet/a575171a72f0f1db8797 to your computer and use it in GitHub Desktop.
Silence python
#!/usr/bin/env python2
from __future__ import print_function
import sys
class shutup(object):
def __enter__(self):
self.stdout = sys.stdout
sys.stdout = self
def __exit__(self, type, value, traceback):
sys.stdout = self.stdout
def write(self, arg):
pass
print("Noisy!")
with shutup():
print("No noisy?")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment