Saturday, June 3, 2023

Module 3: Debugging and Error Handling

Module Three pertained to Python scripting debugging and error handling. I was initially intimidated by this week's assignment. However, I remembered how time consuming last week's assignment was due to my overthinking things and focused on the small details (rather than the big picture).  As such, I completed all portions of this lab in a reasonable time frame and believe that I grasped all concepts well.  I also became more proficient in spotting errors in Python code.  


In the Lab Assignment, we were provided with three different scripts. With the first two scripts, we were required to identify and correct errors to ensure that the script ran as expected. With both of these scripts, there were errors in syntax (spelling, case sensitive errors, etc.), that were preventing the script from running corrections. In some cases, the script was not pointing to the correct directory or location.  We learned about other common errors that occur with python scripting, which included: ) Failing to import the proper modules B)  Failing to include colons after statements (For Example: For, while, try, except statements); C) Conditional vs. assignment statements (ie: Conditional statements use (==), assignment statements (=).

Script 1 Result


Script 2 Result

With regard to Script 3, we were asked not to correct any of the errors in the code, but utilize a "Try-Except" statement, which would allow the script to run successfully. even when there were errors in the code. Python scripts will not run if errors (or exception) occur, which is why it is necessary for us to learn how to bypass some of the errors to run the entire script. This portion of the lab was more time consuming that Scripts 2 and 3, mainly because I did not initially understand the concept at first.  But, after I ran scripts in the Lab Exercise, and read more about the concept, I was able to understand it.  Simply put, the programmer should put the "Try:" statement on the code they would like to "try out" and then put the "Except" statement after the lines of code that the programmer would like to "try" and look for errors. The programmer should be sure to modules that they would need prior to inserting the "try" statement. Below, I have posted a general flow chart for the Try-Except Clause.

Script 3 Result

Script 3 Flowchart ("Try-Except Clause"): 




No comments:

Post a Comment

Analytical Data: Module 5

For Module 5 (Analytical Data), we processed various data sets and created infographics using various programs (ArcGIS, Microsoft Word, Micr...