This week we looked at how to find and resolve errors within scripts. The three main types of errors in Python are syntax errors, exceptions, and logic errors. There are different ways to approach finding and resolving all three, including running a check, using debugging methods, and using the Python Debugger in PythonWin. Python Debugger will take some more practice, however, I feel I made a good start in understanding how to read error statements and resolve errors.
For the lab, three scripts were provided to with errors in them. The first script contained a couple of exceptions, which I found by running the script, reviewing the error messages, and fixing the erroneous code.
 |
| Script 1 printed the names of all the fields in a shapefile. |
The second script contained 8 errors, including typos, incorrect file paths, and incorrect arguments. I found all errors by again, running the code, reviewing the error messages, and fixing the erroneous code.
 |
| Script 2 printed the names of the four layers within an mxd. |
The final script involved adding a try-except statement to "catch" and print the error within a two part script, but allow the script to continue to run. The only challenging part to this part was figuring out where to put the exception part of the try-except statement. I figured it out by referring to our Exercises and realized my problem was mostly incorrect indentation.
 |
| Script 3 is a two part script that turns on labels and layer visibility, then prints data frame info for an mxd. |
No comments:
Post a Comment