python prevent function from printing code example
Example: python prevent print output
import io
import sys
def salute(name):
"""Says hi to someone."""
print('Hi, {}!'.format(name))
# create a text trap and redirect
stdouttext_trap = io.StringIO()
sys.stdout = text_trap
# execute our now mute function
salute('Anne')
# now restore
stdout function
sys.stdout = sys.__stdout__