Python ignores warning errors

created at 06-27-2021 views: 9


Errors are often encountered in python development, but warning usually does not affect the operation of the program, and sometimes it is particularly annoying. Let's talk about how to ignore warning errors.

Before talking about ignoring warnings, let's talk about how to actively generate warning errors. The warnings module is used here. Look at the following code:

import warnings
def fxn():
    warnings.warn("deprecated", DeprecationWarning)
with warnings.catch_warnings():

This produces a warning error


So how to control the output of warning errors? Very simple

import warnings

This ignores the output of warning errors. It's very simple~~

Someone wants to ask how to ignore the warning and error output on the command line? It's also very simple:

python -W ignore

now it's ok

created at:06-27-2021
edited at: 06-28-2021: