This module's lab assignment focused on finding common errors within script and fixing them. It also dealt with more difficult run-time errors and how to handle them with try-except statements.
I was given three pre-written scripts and asked to debug them and make them run properly. The degree of difficulty per script scaled.
The first script template contained two errors. Besides a capitalization error, the most challenging one to find was in a for loop. In the statement for this loop, it read "for fields in field", which could not work as fields had been defined prior to the loop. Once changed to "for field in fields" the script ran properly, returning a list of the field contained in the parks.shp file the script was searching within. Below is a screenshot showing that the new script runs properly.
The second script contained several more errors than the first. Once corrected, the script would print out the names of all of the layers in a project made in ArcGIS Pro. This script contained multiple punctuation and spelling errors. However, the most challenging error I found was the project was named incorrectly in the filepath. Once reviewing my files, I was able to correct this and resolve OS error. The corrected script and its result is shown below.
1
Filepath errors were not something I was looking for initially as
I assumed the prewritten code would have these correct. I was not entirely
familiar with OS Errors, and they do not print much of an error statement
besides the line it occurs on. It took me some time but once I realized that the
filepaths in the prewritten code were not exact to how I had my S drive set up,
I quickly realized this was something I would need to keep an eye on moving
forward.
2
Need to make sure I am closing ArcGIS Pro when using files related
to projects, as this can cause errors. I found myself wanting to keep it open as
I worked in case I had to go back and forth. Like my previous note, the error was
not very apparent when I received it. I had to think about what may be causing
the error and after realizing that the script wanted to create a save, I
figured I must have to close the application.




Comments
Post a Comment