How to solve the problem of python error reporting by lost sys.stdou
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.