Errors are an inevitable part of scripting. It's not a matter of if they will happen, but when and where. Knowing how to find the when and where is a vital part of scripting. Syntax errors, exceptions, and logic errors are all possible types of errors. There are a number of ways to find where errors exists. The PythonWin toolbar is a good place to start. It can tell you if a an error occurred and on what line. The debugger tool in PythonWin is also another useful tool in finding errors. Being able to step through lines of code one at a time can pinpoint the location that a script stops working. Commenting out lines of code and adding print statements are also helpful in finding errors. Lastly, the try-except tool can be used to allow a script to run even if specific sections of code contain an error.
This weeks assignment was to locate script errors and correct them and to use the try-except command to show how a script can run even with an error present.
The first script contained two errors that needed to be found and fixed to display the names of the airports from module 6 data.
|
Script1_Results |
The second script contained 8 errors that needed to be corrected. I was able to locate the errors by using selective commenting and interpreting the interactive window results.
|
Script2_Results |
The third script contained an error, but instead of fixing the error, we were to insert a try-except command that would allow the script to run even though there was an error in part A.
|
Script3_Results
|