Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the reason for the Python warning warning?

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report