Wednesday, June 5, 2019

GIS Programming - Module 3 Lab

Python 3.6.6 |Anaconda, Inc.| (default, Jun 28 2018, 11:27:44) [MSC v.1900 64 bit (AMD64)] on win32

>>> print ("Hello Everyone!") 

Hello Everyone!

This weeks lab was all about Debugging! Debugging is probably one of the most important aspects of Python as it allows you to catch all the errors in your code that are causing it to fail. For this weeks lab, I was given three template scripts that contained errors. Two of these scripts required me to fix the errors within them, and the third required me to write a try-except statement that bypassed the error in the first part of the script and then run the second part. In Spyder, the Debugging tool is invaluable. With the ability to go line by line and find errors within your code is essential to ensure you're catching and proofing every line of code. For the first two scripting examples, this is the flow methodology I used:

Start
>>>Look over the code to find individual errors

->>>Run the code and find any errors missed individually
or
->>>Run the debugging tool line by line and fix errors.

>>>Run the successfully fixed code and get desired results
Stop

Once the debugging process had been completed, the scripts ran successfully with these results:



The first two examples contained multiple case-sensitive errors and attribute name errors that cause the interpreter to get hung up on as Python is very case sensitive.

For the third script, I had to write a try-except statement that would run a part of code even with an apparent error/exception. For this portion my methodology was as follows:

Start
>>>Look over the code to find errors within Part A
>>>Run the code using the debugging tool to ensure the error is where it is
>>>Write a try-except statement that will print the error exception message without hang up
>>>Ensure Part B of script runs
>>> Run both parts getting the exception message and Part B success.
Stop

As you can see in the results below, the script ran as intended, printing the Exception/Error message of Part A without hanging up the script and successfully running Part B.


No comments:

Post a Comment