以prevent从Python中的批次控制台打印功能 [英] To prevent a function from printing in the batch console in Python
本文介绍了以prevent从Python中的批次控制台打印功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
那么,标题似乎对我足够了。
我使用的一些功能,在一些点在控制台打印的东西。
正如我无法修改它们,我想知道是否有一个解决方案,同时使用这些功能不打印。
Well, the headline seems to me sufficient. I use some function that at some points print something in the console. As I can't modify them, I would like to know if there is a solution to not printing while using these functions.
非常感谢!
尼科
推荐答案
是的,你可以重定向为sys.stderr
:
import sys
import os
sys.stdout = open(os.devnull, "w")
my_nasty_function()
sys.stdout = sys.__stdout__
只需更换 my_nasty_function
与您的实际功能。
编辑:现在应该在藏汉窗口工作,并利用了 SYS .__标准输出__
,而不是备份变量
Now should work on windows aswell and makes use of sys.__stdout__
instead of a backup variable.
这篇关于以prevent从Python中的批次控制台打印功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文