Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Python traceback.print_exc() prints to stdout or stderr?

I've read some Python docs, but I can't find where the print_exc function prints. So I searched some stack overflow, it says "print_exc() prints formatted exception to stdout". Link

I've been so confused.. In my opinion, that function should print to stderr because it's ERROR!.. What is right?

like image 209
youngminz Avatar asked Dec 02 '15 15:12

youngminz


1 Answers

It prints to stderr, as can be seen from the following test:

$ 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 <module>
     raise IOError()
IOError
$ python test.py > /dev/null
Traceback (most recent call last):
  File "test.py", line 2, in <module>
     raise IOError()
IOError
$ python test.py 2> /dev/null
$
like image 77
Eric Renouf Avatar answered Oct 19 '22 07:10

Eric Renouf