Created
March 4, 2019 16:33
-
-
Save heethesh/e0317d405d96d906b478c8400715f61e to your computer and use it in GitHub Desktop.
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 | |
import sys | |
def block_printing(func): | |
def func_wrapper(*args, **kwargs): | |
# Block all printing to the console | |
sys.stdout = open(os.devnull, 'w') | |
sys.stderr = open(os.devnull, 'w') | |
# Function call | |
value = func(*args, **kwargs) | |
# Enable all printing to the console | |
sys.stdout = sys.__stdout__ | |
sys.stderr = sys.__stderr__ | |
return value | |
return func_wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage