我已经阅读了一些Python文档,但我找不到print_exc函数的打印位置.所以我搜索了一些堆栈溢出,它说" print_exc()
打印格式化异常到stdout".链接
我一直很困惑..在我看来,这个功能应该打印到stderr,因为它是错误的!..什么是对的?
它打印到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, inraise 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 $