Debugging the Bugs in Python Scripts

The third module covered the debugging of scripts. I am now used to using the Spyder interface, and dare I say that I really like it. It makes it easy to track down syntax errors, and the debugging toolbar let me filter the code line by line to ease the overwhelming feeling of tracking down small mistakes within dozens of lines and hundreds of characters. 

For the first script, there were some basic errors to fix. These errors were related to spelling and capitalization, which Python is sensitive to. The results used layers of a ArcGIS Pro project for this result:


The second script also contained basic errors of the same nature, ensuring we are paying attention to the spelling and consistency of our defined variables. Referencing the same ArcGIS project, this script produced this result:


The last script let us try our luck at a try-except statement, and at first I felt very overwhelmed by the possibilities and where to start. I slowed it down and took it one step at a time, writing out my statement at the bottom of the script. It seemed to make sense, but did not work. Soon, I realized I needed to move my statement to contain the block of data that contained the error. My script then ran properly, and gave me a short print of the error it worked around. The ArcGIS project was once again referenced, and this script produced this result:


Usually, I remember these lessons because of the challenge. This time, I will remember the sense of accomplishment at debugging my scripts efficiently. I am so grateful to be learning how to script in Python! Now that we know the basics of the debugging process, and how to use a try-except statement, I am ready to see what is next. 

Comments