import jwutils print "This is without muted output" with jwutils.MuteStdIO(): print "This is with muted output" with jwutils.MuteStdIO(): print "This will have an error" print "Second suppressed line of output" print "Third suppressed line of output" raise Exception("Something went wrong") print "Output is unmuted again"