Home  >  Article  >  Backend Development  >  How to ignore warning errors in Python

How to ignore warning errors in Python

高洛峰
高洛峰Original
2016-10-19 13:36:303969browse

I was running a python file and kept getting warning errors. I was very depressed, so I thought I could ignore these errors.

Here’s how to ignore these warnings.

python -W ignore yourscript.py

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

If you don’t want to use the above method, you can add the following code directly at the beginning of the python source code:

import warnings
warnings.filterwarnings("ignore")

This way you can ignore the python warning Wrong


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn