Wednesday, June 10, 2015

Lab 4 - Debugging and Error Handling

This lab was about learning to debug and handle errors in Python code. We also got some experience with the debugger in PythonWin. I think it’s really helpful to learn some of this before writing code too much more complicated. In this lab, we had three scripts with which we had to handle errors in different ways.
Part I was basically finding and correcting errors, so that the code would print out the field names of the “parks” shapefile. In this case, we knew we only had 2 errors, which of course when we write a code we won’t know. Below is a screenshot of the output of the first corrected script.



The second script had a total of eight errors, most of which were pretty easy for me to spot. This script was to print the layers active in a data frame. This had several errors, some of which were in commands we have not used yet, but using a search engine to look up the command in question (mainly to see what the syntax normally looked like) was very helpful. Below is a screenshot of my output.



The third part was trickier. We were to bypass the error using a try-except statement, where Part A returns an error message, but Part B runs correctly. This was mainly trial and error for me as far as where to place the try-except statements. I imagine I will get faster at it with more practice. Below is a screenshot of my output.




I feel having some prior experience with debugging helped a lot. The new concepts to me were really learning how to use the debugger tool for Python and using the try-except statements. I feel this was a good lab to help us get comfortable with the types of errors we will see in future labs.

No comments:

Post a Comment