How do I block python RuntimeWarning from printing to the terminal?

56,835

Solution 1

This may be useful to you, I think the issue has been pretty solved in this question: How to disable python warnings

Solution 2

All what you need is suppress it exactly as described in official documentation: https://docs.python.org/2/library/warnings.html#temporarily-suppressing-warnings

Share:
56,835
Kieran Hunt
Author by

Kieran Hunt

Currently working as a postdoc in the Department of Meteorology at Reading University. PhD in atmospheric physics, with particular interest in the processes governing tropical depressions in south Asia. Master's in astrophysics/atmospheric physics with a thesis in fractal geometry and electronic engineering.

Updated on January 10, 2020

Comments

  • Kieran Hunt
    Kieran Hunt over 4 years

    I have some python code that, at some point, takes the axis means of a reasonably sparse array with nans in. Every time I run the code it raises a RuntimeWarning.

    I know what's causing the warning, it's intentional, and it doesn't affect the output. It is, however, quite irritating to be presented with the warning every time I run the program - so, is there a cheap and nasty way to prevent them from being printed to the terminal?