Wednesday, June 14, 2017

Module 4 - Python Debugging and Error Handling

This week's lab focused on finding errors in python scripts and fixing them, thus allowing the script to run successfully.  We used tools such as the check button and the debugger to identify the script errors and learned a little about what each error means.  I found that simply running the code and reading the error message in the interactive window to be the best way to identify errors.  I had a few issues with the debugger, such as the my yellow triangle disappearing and the debugger simply not working occasionally.  I'd like to spend more time figuring out the usefulness of the debugger tool. The lab was divided into three parts with unique instructions for each.  Screenshots with descriptions of my process can be found below.

Part one was a simple script that contained 2 errors.  I identified these errors as syntax errors pretty easily using the check button.  I was able to correct these and move on to the next script.  Script 1 results are found below.
Script #1 Result

Part two was a longer script which contained 8 errors.  This section was very challenging and I was concerned for a while that I wouldn't be able to find all eight errors.  I spent a lot of time trying to use the debugger tool which I didn't find very helpful.  I ran the script without the debugger and identified the errors by the error message in the interactive window.  I really like that the error messages tell you which line the error is on.  I found myself doing quite a bit of guess and checking to figure out how to correct my errors.  Although these were educated guesses, I know I need more practice debugging. Script 2 results are found below.
Script #2 Result

In part 3 we were not asked to fix an error but instead use a try-except statement to "catch" the error and and allow the script to still run even with the error.  Using the try-except statement, I was able to insert a custom sentence for the machine to print when it identified that certain error.  I was able to wrap my head around the concept of a try-except statement after reading a section on them in chapter 11.  The results of this script are seen below.
Script #3 Result

No comments:

Post a Comment