Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the reason for the Python warning warning?

Shulou Source: shulou.com Published: 2022-06-02 22:42:08 09月24日 Update

This article will explain in detail the reasons for the emergence of Python warning warnings, the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

Error reports are often encountered in python development, but warning usually does not affect the running of the program, and is sometimes particularly annoying, so let's talk about how to ignore warning errors.

Before we talk about ignoring warning, let's talk about how to actively generate warning errors. Here we use the warnings module. See the following code:

Import warningsdef fxn (): warnings.warn ("deprecated" DeprecationWarning) with warnings.catch_warnings (): warnings.simplefilter ("ignore") fxn ()

This results in a warning error

So how do you control the output of warning errors? It's simple

Import warningswarnings.filterwarnings ("ignore")

This ignores the output of warning errors. It's very simple, isn't it?

Someone wants to ask how to ignore the output of warning errors on the command line. It's also very simple:

Python-W ignore yourscript.py

So it's OK.

Content extension:

1) warning in code

Import warningswarnings.filterwarnings ("ignore")

2) ignore the output of warning errors on the command line:

Python-W ignore yourscript.py

So much for sharing the reasons for the Python warning warning. I hope the above content can be helpful to you and learn more. If you think the article is good, you can share it for more people to see.

Tags: Error output content reason code command article more knowledge article good initiative situation module program quality reference help development influence Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Redmi OPPO Reno Xiaomi Linux