GIS Programming Week 3
This week I learned the basics of fixing errors within your Python script, a process called debugging. I was provided with a few scripts that contained several errors, and it was up to me to address the issues and make the script functional. To find the problems in the code to
debug them, I first ran the script to see what errors occurred. The error
messages in the Python Shell were quite helpful as they told me what type of
error it was, as well as the specific line it came from. Most of the troubles
were simple spelling or syntax errors, which were easy to fix and help further
familiarize me with the proper grammar of Python. I found the entire process
quite enjoyable and rewarding. Below is the final output of the first two scripts I fixed, which retrieved shapefile information from a project in ArcGIS pro.
For the final script, I was told to not fix any errors found, but to instead employ a "try/except block", a tool used to work around possible errors and successfully run the rest of the code. This script was split into two parts, and I discovered an exception error in Part A due to a missing
path in one of the lines, so instead of fixing it, I used a try/except block to work around the error and run Part B. I initially placed
the block just above the line of code that was causing the issue, only to
encounter another. Now, any following line using the variable from the line I
had placed the block on was now triggering an error, as the variable was no
longer defined. I realized I had to put the rest of the related lines under the
“try” block, and use “except” to call out the specific error, which happened to
be a type error. With this fix, I was able run the script successfully while
outputting an error message detailing the problem. The final output and flowchart
detailing my process are pictured below.



Comments
Post a Comment