0

I am using odeint from scipy.itegrate in python. Sometimes I get integrating errors like,

lsoda-- at current t (=r1), mxstep (=i1) steps
taken on this call before reaching tout
in above message, i1 = 500 in above message, r1 = 0.4082154636630D-03

I would like to NOT print those errors on the screen. Is there any way to print them directly to some error file? I just don't want them to be printed on the screen as I am printing something else there in big loop, and automatically to the result file. Thanks

Kasia Kowalska
  • 143
  • 2
  • 10
  • Possible duplicate of [How to redirect stderr in Python?](https://stackoverflow.com/questions/1956142/how-to-redirect-stderr-in-python) – atru Mar 15 '18 at 12:56
  • 1
    I found perfect solution here: [answered question][1] https://stackoverflow.com/questions/31681946/disable-warnings-originating-from-scipy – Kasia Kowalska Mar 15 '18 at 14:10

1 Answers1

0

If these messages are printed on the stderr, you can capture it and redirect to a file. A minimal implementation is

import sys
sys.stderr = open('the_log_file_for_errors', 'w')

Another, more complex, way can be to encapsulate the code that can give the error in a try...except block, in the except block you can do log the error on a file with some more details (like input params and so on) to check after.

Gianluca
  • 3,227
  • 2
  • 34
  • 35