Skip to main content Accessibility help
×
Hostname: page-component-77c89778f8-sh8wx Total loading time: 0 Render date: 2024-07-20T13:02:56.460Z Has data issue: false hasContentIssue false

Appendix

Published online by Cambridge University Press:  05 June 2012

Allen B. Downey
Affiliation:
Olin College of Engineering, Massachusetts
Get access

Summary

Different kinds of errors can occur in a program, and it is useful to distinguish among them in order to track them down more quickly:

  • Syntax errors are produced by Python when it is translating the source code into byte code. They usually indicate that there is something wrong with the syntax of the program. Example: Omitting the colon at the end of a def statement yields the somewhat redundant message SyntaxError: invalid syntax.

  • Runtime errors are produced by the interpreter if something goes wrong while the program is running. Most runtime error messages include information about where the error occurred and what functions were executing. Example: An infinite recursion eventually causes the runtime error “maximum recursion depth exceeded.”

  • Semantic errors are problems with a program that runs without producing error messages but doesn't do the right thing. Example: An expression may not be evaluated in the order you expect, yielding an incorrect result.

The first step in debugging is to figure out which kind of error you are dealing with. Although the following sections are organized by error type, some techniques are applicable in more than one situation.

SYNTAX ERRORS

Syntax errors are usually easy to fix once you figure out what they are. Unfortunately, the error messages are often not helpful. The most common messages are SyntaxError: invalid syntax and SyntaxError: invalid token, neither of which is very informative.

Type
Chapter
Information
Python for Software Design
How to Think Like a Computer Scientist
, pp. 231 - 240
Publisher: Cambridge University Press
Print publication year: 2009

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Save book to Kindle

To save this book to your Kindle, first ensure coreplatform@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

  • Appendix
  • Allen B. Downey, Olin College of Engineering, Massachusetts
  • Book: Python for Software Design
  • Online publication: 05 June 2012
  • Chapter DOI: https://doi.org/10.1017/CBO9780511813832.022
Available formats
×

Save book to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

  • Appendix
  • Allen B. Downey, Olin College of Engineering, Massachusetts
  • Book: Python for Software Design
  • Online publication: 05 June 2012
  • Chapter DOI: https://doi.org/10.1017/CBO9780511813832.022
Available formats
×

Save book to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

  • Appendix
  • Allen B. Downey, Olin College of Engineering, Massachusetts
  • Book: Python for Software Design
  • Online publication: 05 June 2012
  • Chapter DOI: https://doi.org/10.1017/CBO9780511813832.022
Available formats
×