Understanding error messages in Python: Difference between revisions
Mr. MacKenty (talk | contribs) (Created page with "right|frame|Programming<ref>http://www.flaticon.com/</ref> = Understanding error messages in Python = == Syntax Errors == Syntax errors, also known...") |
Mr. MacKenty (talk | contribs) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 15: | Line 15: | ||
<syntaxhighlight lang="python"> | <syntaxhighlight lang="python"> | ||
1. File "/Users/bmackenty/Documents/python_scratch_folder/hello_world.py", line 1 | |||
2. print" Hello there" | |||
3. ^ | |||
SyntaxError: invalid syntax | 4. SyntaxError: invalid syntax | ||
</syntaxhighlight> | </syntaxhighlight> | ||
* On line 1, we see the name of the file we are running, and the line number for the error. | |||
* On line 2, we see the actual line of code. | |||
* On line 3, we see the carat character ^ which is pointing the problem on line 2 | |||
* On line 4, we see the actual error. There are many different types of errors. | |||
One important point. Often, an error happens on the line before the stated error. Please use syntax highlighting and your IDE to help you avoid syntax errors. | |||
== References == | == References == |
Latest revision as of 09:57, 20 August 2020
Understanding error messages in Python[edit]
Syntax Errors[edit]
Syntax errors, also known as parsing errors, are perhaps the most common kind of complaint you get while you are still learning Python[2]
Exceptions[edit]
Even if a statement or expression is syntactically correct, it may cause an error when an attempt is made to execute it. Errors detected during execution are called exceptions and are not unconditionally fatal.[3]
How to read an error message[edit]
An error MIGHT look something like this:
1. File "/Users/bmackenty/Documents/python_scratch_folder/hello_world.py", line 1
2. print" Hello there"
3. ^
4. SyntaxError: invalid syntax
- On line 1, we see the name of the file we are running, and the line number for the error.
- On line 2, we see the actual line of code.
- On line 3, we see the carat character ^ which is pointing the problem on line 2
- On line 4, we see the actual error. There are many different types of errors.
One important point. Often, an error happens on the line before the stated error. Please use syntax highlighting and your IDE to help you avoid syntax errors.