当前位置:  开发笔记 > 编程语言 > 正文

Python traceback.print_exc()是否打印到stdout或stderr?

如何解决《Pythontraceback.print_exc()是否打印到stdout或stderr?》经验,为你挑选了1个好方法。

我已经阅读了一些Python文档,但我找不到print_exc函数的打印位置.所以我搜索了一些堆栈溢出,它说" print_exc()打印格式化异常到stdout".链接

我一直很困惑..在我看来,这个功能应该打印到stderr,因为它是错误的!..什么是对的?



1> Eric Renouf..:

它打印到stderr,从以下测试可以看出:

$ cat test.py
try:
    raise IOError()
except:
    import traceback
    traceback.print_exc()
$ python test.py
Traceback (most recent call last):
  File "test.py", line 2, in 
     raise IOError()
IOError
$ python test.py > /dev/null
Traceback (most recent call last):
  File "test.py", line 2, in 
     raise IOError()
IOError
$ python test.py 2> /dev/null
$

推荐阅读
wurtjq
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有