Last active
August 29, 2015 14:05
-
-
Save jledet/a575171a72f0f1db8797 to your computer and use it in GitHub Desktop.
Silence python
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/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