python - 如何将python中的stdout重定向到函数?
问题描述
我知道我可以将标准输出重定向到一个文件:
stdout = open("file", "a")
但是我如何将它发送到 python 函数。我正在使用无头服务器,我想将输出重定向到易于监控的外部源。
我想要做:
def my_print_handler():
# do something useful with the output other than printing it to a screen nobody sees
stdout = my_print_handler()
print ("Hello World") # sent to my_print_handler rather than screen
解决方案
推荐阅读
- zabbix - 如何计算 s3 存储大小并通过电子邮件发送汇总?
- javascript - 如何根据父级宽度创建子级
- android - Android 10以上手机如何开启WiFi热点
- python-3.x - 在多次运行代码并获得随机结果后是否可以找到 random.seed 值
- c# - 当应用程序位于 Azure 中时,如何使用 MSAL 进行身份验证?
- blockchain - 如何获取给定代币的所有历史 Uniswap/Pancakeswap 交易
- python-3.x - 有什么方法可以一步一步在图例中添加标签吗?
- python - Manipulate ordering/sorting of Multirow columns in a pandas DataFrame
- python - Python Matplotlib - 如何绘制 df 的前 20 名?
- mysql - 将表转换为另一个存储时,MYSQL CPU 会变高