In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are the common error messages in Python". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the common error messages in Python"?
1 、 IndentationError: unindent does not match any outer indentation level
Explanation: indent error, python indents the code not by {} wrapping the code, but by tab or spaces, if
If there is no alignment before and after indentation, this error will be reported
2. NameError:name 'test' is not defined
Explanation: if you do not define a variable called test, you will report this error if you directly use test to execute business logic.
3 、 SyntaxError: invalid syntax
Explanation: grammatical error. The only thing is not the error that occurs at run time.
It represents an incorrect structure in the Python code, and the program cannot be executed until it is corrected
And for example, SyntaxError: EOL while scanning string literal, which is common for beginners, indicates that your string is not encapsulated in quotation marks.
4 、 IndexError:list index out of range
Explanation: the index is out of the sequence range, such as li= ['ajar,' baked,'c'], and the index is 0memt 1 and 2. When you visit li [3], you will report an error.
5 、 KeyError:'test'
Explanation: there is no key,a = {'name':' jack'} of test in the dictionary. This error is thrown when you call a ['age'].
6. IOError: [Errno 2] no such file or directory: "/ home/a.txt"
Explanation: the path or file / home/a.txt was not found, which appears when you use open or other read system path files
7. AttributeError:'a' object object has no attribute 'b'
Explanation: if this b is not in an instantiated an object and you call it, for example, a.b will report this error.
8. TypeError: 'NoneType' object is not callable
Explanation: you are currently calling a None, and you are trying to do some operations such as None () on the None object, and at the same time
Similar to 7, if you call a property such as None.b on a None object, it will also report an error of 7.
This error usually occurs when an available object is returned and the operation is performed, and when None is returned, you perform the operation without verification
For example, there is a function def a (name):... If you do not pass parameters or do not pass parameters, you will also report to Typeerror
For example, TypeError: a () missing 1 required positional argument: 'name'
Another example is TypeError: Can't convert 'int' object to str implicitly
It means you're trying to add an integer to a string.
9. ValueError: invalid literal for int () with base 10: 'abc'
Explanation: the parameter type of the object passed is inaccurate, for example, there is an object a = 'abc' you attempt to int (a) to him.
This error will occur.
10. FileNotFoundError: [Errno 2] No such file or directory:'/ home/helloworld.py'
Explanation: similar to 6, when reading a file, it is possible to throw this error indicating that the path or file was not found
11 、 io.UnsupportedOperation: not writable
Explanation: when you operate on a file, this error will be reported if you do not have the relevant permissions.
12. ImportError: No module named 'requests'
Explanation: you did not import this requests package but used it in your business
Or, for example, I tried to import a non-existent method from requests from aa from requests.
You will report ImportError: cannot import name 'aa'.
There is a slot here, for example, we execute python test.py under the test.py path.
However, if there are packages or functions in test.py that call other paths on the current path, they will also report the relevant importerror
In principle, it is an error in the current py location that you execute under the current path, and the code will only look for the current path as the inspiration path.
So it's best to execute it at a higher level, or add the address of the report to be imported to the sys.path under the current py.
Thank you for your reading, the above is the content of "what are the common error messages in Python". After the study of this article, I believe you have a deeper understanding of the common error messages in Python, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.