I have a large project consisting of sufficiently large number of modules, each printing something to the standard output. Now as the project has grown in size, there are large no. of
# I want to do something like this.
sys.stdout = None # this obviously will give an error as Nonetype object does not have any write method.
def write(*args): pass
dp = DontPrint()
sys.stdout = dp
import os import sys f = open(os.devnull, 'w') sys.stdout = f
f = open('nul', 'w') sys.stdout = f
f = open('/dev/null', 'w') sys.stdout = f