Created
March 22, 2013 14:22
-
-
Save radaniba/5221639 to your computer and use it in GitHub Desktop.
The essential problem is how to not get output from a program. Let me explain: Ete2, a Python module for representing phylogenies, has a number of dependencies (MySQLdb, Numpy, PyQt, etc.) that it doesn't necessarily need and it xcan be installed without them. If you don't use the associated functionality, you won't need these dependencies. But,…
This file contains hidden or 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
import os, sys | |
class SuppressAllOutput (object): | |
def __enter__(self): | |
sys.stderr.flush() | |
self.old_stderr = sys.stderr | |
sys.stderr = open('/dev/null', 'a+', 0) | |
sys.stdout.flush() | |
self.old_stdout = sys.stdout | |
sys.stdout = open('/dev/null', 'a+', 0) | |
def __exit__(self, exc_type, exc_value, traceback): | |
sys.stderr.flush() | |
sys.stderr = self.old_stderr | |
sys.stdout.flush() | |
sys.stdout = self.old_stdout | |
print >>sys.stdout, "printing to stdout before suppression" | |
print >>sys.stderr, "printing to stderr before suppression" | |
with SuppressAllOutput(): | |
import ete2 | |
print >>sys.stdout, "printing to stdout during suppression" | |
print >>sys.stderr, "printing to stderr during suppression" | |
print >>sys.stdout, "printing to stdout after suppression" | |
print >>sys.stderr, "printing to stderr after suppression" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I fixed it: