GIS Programming Module 3 – Debugging and Error Handling
Module 3 assignment dealt with debugging and removing errors in Python code. A Python error can be either a syntax error or a run-time error. Syntax errors are errors that are detected before the code is sent to the Python interpreter and prevent the code from running. Syntax errors will cause the code to abruptly stop. Syntax errors are generally caused by misspelling keywords, missing punctuation, or not indenting correctly. Run-time errors are logical errors in the code that do not prevent the code from running but produce incorrect results. Examples of run-time errors would be dividing by zero, undefined variables, trying to open a file that does not exist, and many others. Run-time errors throw an exception that can be caught and handled using try-except statements.
Script 1 of the assignment prints a list of all the fields in the parks shape file. The script contained one run-time error and one syntax error. The run-time error was a NameError caused by a variable name that was not the same case as the defined variable. The variable FC was assigned to the name of the shape file but the lowercase “fc” was used as a parameter a function. The syntax error was a missing colon at the end of a for loop.
Flow chart for Script 1
Script 2 opens an ArcGIS project file and prints the spatial reference of the dataset and then prints a list of the layers the map contains. The script had many errors that mostly dealt with incorrect spelling or wrong case for variable or function names.
Flow Chart for Script 2
Comments
Post a Comment