Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 306
Kieran Hunt Avatar asked Jan 09 '15 15:01

Kieran Hunt


People also ask

How do I stop the print warning in Python?

If you want to stop the process for warnings like exceptions, set action of warnings. simplefilter() to 'error' .

What is DeprecationWarning in Python?

DeprecationWarning. Base category for warnings about deprecated features when those warnings are intended for other Python developers (ignored by default, unless triggered by code in __main__ ).

How do you create a warning message in Python?

The warn() function defined in the ' warning ' module is used to show warning messages. The warning module is actually a subclass of Exception which is a built-in class in Python.

What is runtime warning?

A RuntimeWarning is used to signal to the runtime framework that a non-fatal error has been encountered. Server startup will proceed as usual. See Also: com.ibm.wsspi.runtime.component.WsComponent#start() , Serialized Form.


1 Answers

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

like image 55
Palmer Avatar answered Oct 16 '22 12:10

Palmer