📅  最后修改于: 2022-03-11 14:45:19.768000             🧑  作者: Mango
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__