How to ignore warning errors in Python

高洛峰
Release: 2016-10-19 13:36:30
Original
3968 people have browsed it

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()
Copy after login

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")
Copy after login

This way you can ignore the python warning Wrong


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template