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

How to solve the problem of python error reporting by lost sys.stdou

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces the python error lost sys.stdou how to solve the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this python error lost sys.stdou how to solve the article will have a harvest, let's take a look.

Error occurs

The error report means that the sys.stdout is lost. Then the editor runs all the code in this folder, and there is an error like this.

Only after asking for help did I know that my io module had been replaced, and then the editor looked at his project folder and found the culprit:

Yes, it is the module called io, the editor once called a python file named io, and then he replaced the built-in io module, and then all operations involving the io module can not be used.

Solution method

Since it's the name, it's OK to change it. After renaming that file, my project is back to normal.

The thinking caused by this

Since renaming the io,io module will not work, then renaming it to requests will not be able to run the ruquests module? After a try, it was found that this was true. The principle is simple: when searching for packages, python will first search for the module in the project, if so, use the module within the project, and if not, look for it in the list called sys.path. All the modules that come with python and the third-party modules installed by pip are here.

How to avoid

From the above conclusion, we can get a very simple way to avoid it-since naming is the same as the module, we will not have such an error as long as we avoid these module names. This leads to the specification for naming python files-- do not name py files with module names!

This is the end of the article on "how to solve python error lost sys.stdou". Thank you for your reading! I believe you all have a certain understanding of the knowledge of "how to solve python error lost sys.stdou". If you want to learn more knowledge, you are welcome to follow the industry information channel.

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