I am trying to suppress the print statements in a function imported from a library. I use Python 3.6 in Jupyter Notebook.
I used:
sys.stdout = open(os.devnull, "w")
x = myfunction()
sys.stdout = sys.__stdout__
Unfortunately this succeeds in suppressing the print statements, but not in reinstating them afterwards. So I cannot print anything after this unless I restart the kernel.
How could I fix this?