在我的程序中有很多print
函數(python 2.7
)。有什麼辦法可以添加幾行然後所有的輸出可以重定向到stderr
?我想要的是Python代碼,但不是Linux管道。在python中,我可以將打印函數的輸出重定向到stderr嗎?
例如,我的計劃是這樣的:
print 'hello world'
我想添加一些代碼,如:
redirect_output_to_stderr()
print 'hello world'
然後所有的輸出可以重定向到stderr
。
我知道print >> sys.stderr, 'hello world'
可以實現我的目標,但它是否可以防止修改已存在的代碼?
code_是使用shell的重定向命令。 – 2013-04-07 08:42:07
哦,我想我需要的是防止修改現有的「打印」功能。感謝你提到:) – waitingkuo 2013-04-07 08:45:08