python error collection

hello everyone

I'm here again, today let's take a look at some common exception errors in python

When it comes to errors in python, we always have a headache.
Please add image description
Now we have to learn to recognize the types of errors

In this way, when we report an error, we can know what is the reason for the error~(https://jq.qq.com/?_wv=1027&k=RFkfeU8j)

1.SyntaxError

SyntaxError syntax error

The small details that people are most likely to ignore when writing code

I mean, I will run towards you when an abnormal error is reported, and let you see the error that occurred at that time, and see if you have experienced this error.

SyntaxError: EOL while scanning string literal

Ah, this is really careless.
This error is because another quotation mark is missing in my grammar.
The format of the statement in python is incorrect. The
quotation marks and parentheses do not appear in pairs,
such as missing semicolons, quotation marks, Less or more parentheses,
wrong keywords, mixing of Chinese and English characters, etc. will cause errors.
The most common is the mixing of Chinese and English characters.
When typing the code, the Chinese and English input methods will be switched, and
sometimes you will forget to key in English . I have switched to Chinese,
especially in the character symbols, which
are prone to errors and not obvious.
Python is very sensitive to the grammar format. We
must keep the grammar format in mind.
The basic grammar format needs to be memorized and practiced.
Please add image description

2.ModuleNotFoundError

ModuleNotFoundError Module not found,

When you import the module, there is no problem,

But when running the code or project, oh well, it will come when an error is reported (painful), I have also experienced countless times of errors like this, and in countless experiences, I finally found a solution to this problem, Let's see the error message

ModuleNotFoundError: No module named ‘progress’

This error message shows that there is no progress for this module. At that time, I went to Baidu to search because I did not

pip install, so I installed this module. Sure enough, the error is far away from me (great), but,

This is just a solution,
but another is to install but still prompt that the module is not found,
that is because the called module is different from the called module path configuration,
or a py file name is different from the called module The module names are the same, resulting in a naming conflict.
The solution is to put the configuration path of the module in the same path, and if there is a
naming conflict, just modify the duplicate py file name.

insert image description here

3.NameError

NameError variable name error

NameError: name ‘download’ is not defined

This error message is that the variable name is not defined.
This error
is often encountered when typing code (it hurts my head), and
I was also devastated by this error.
Finally, let me find a way The way it goes away from me.
The most common solution to the error that has not been defined just now is to define the variable name,
but one is already defined,
but it still prompts that the error is not defined.
This error is because of the python version, which
is incompatible ,
the solution to this is to be familiar with the detailed rules of python variable names.
insert image description here

4.AttributeError

AttributeError attribute error

AttributeError: ‘list’ object has no attribute ‘testVec’

This error is that list does not have this attribute. This error is because ',' is marked as '.'. We all know that '.' must be defined in the class to have properties. It is useless to write it out of thin air.

5.ValueError

ValueError parameter error

ValueError: invalid literal for int() with base 10: ‘abc’

A Python ValueError is raised when a function receives an argument of the correct type but an inappropriate value. As for the above error int('abc'), the int function can accept string types, but the 'abc' string does not have the meaning of representing an integer.

Detailed error report is here

The following are also frequently encountered error problems, everyone should keep in mind

TypeError type error

IndexError index error

KeyError key error

ImportError Failed to import module/object

FileNotFoundError file error

If there are any additions and mistakes, please comment below, I will take a serious look at it~

Guess you like

Origin blog.csdn.net/m0_67575344/article/details/124355087