5 ArcPy Tricks I Wish I’d Learned in Year One

If you write Python for ArcGIS Pro, you learn these eventually — usually the hard way, at 4:45 PM on a Friday, staring at a schema lock. Here’s the short version, so you don’t have to.

1. Always use with blocks for cursors (goodbye, schema locks)

The old-style cursors left locks hanging around if your script crashed halfway through. The da cursors used as context managers clean up after themselves, and passing an explicit field list plus a where_clause keeps them fast.

import arcpy

fc = r"C:\data\wells.gdb\producing_wells"
fields = ["WELL_NAME", "STATUS", "PROD_BBL"]

with arcpy.da.SearchCursor(fc, fields, where_clause="STATUS = 'Active'") as cursor:
    for row in cursor:
        print(row[0], row[2])

Rule of thumb: if you’re not using with arcpy.da.SearchCursor, you’re doing it the hard way.

2. Do your temp work in the memory workspace

Writing every intermediate output to disk is the slowest thing most scripts do. The memory workspace lives in RAM — use it for everything except your final output.

arcpy.env.overwriteOutput = True

temp = r"memory\wells_buffer"
arcpy.analysis.Buffer(fc, temp, "500 Meters")

# ...clip, dissolve, join, whatever you need...

arcpy.conversion.FeatureClassToFeatureClass(temp, gdb, "wells_buffer_final")

On big jobs this is the difference between a coffee break and a lunch break. (In old ArcMap scripts this was in_memory; in Pro, it’s memory.)

3. Let Describe do your homework

Before you write defensive code checking whether a field exists or what coordinate system you’re in, remember that one Describe call tells you almost everything:

desc = arcpy.Describe(fc)
print(desc.shapeType)              # "Point", "Polyline", "Polygon"...
print(desc.spatialReference.name)  # "NAD 1983 UTM Zone 14N", etc.
print([f.name for f in desc.fields])

I use this at the top of any script that accepts someone else’s data. Trust, then verify — programmatically.

4. Turn scripts into script tools with GetParameterAsText

A script only you can run from an IDE is a liability. Three lines turn it into a proper geoprocessing tool with a dialog box that anyone on the team can use inside Pro:

import arcpy

input_fc    = arcpy.GetParameterAsText(0)  # Feature Layer
buffer_dist = arcpy.GetParameterAsText(1)  # e.g. "500 Meters"
output_fc   = arcpy.GetParameterAsText(2)  # Feature Class

arcpy.analysis.Buffer(input_fc, output_fc, buffer_dist)
arcpy.AddMessage(f"Buffered {input_fc} by {buffer_dist}")

Then right-click a toolbox in Pro → Add → Script, point it at your .py, and define the three parameters. Congratulations — you now ship tools, not scripts.

5. Make your failures tell you what happened

A bare traceback from a failed geoprocessing tool is nearly useless. Catch arcpy.ExecuteError separately and print the real messages:

try:
    arcpy.analysis.Buffer(fc, out_fc, "500 Meters")
    arcpy.AddMessage("Buffer complete.")
except arcpy.ExecuteError:
    arcpy.AddError(arcpy.GetMessages(2))  # the REAL error, not the wrapper
except Exception as e:
    arcpy.AddError(f"Unexpected failure: {e}")

GetMessages(2) returns just the error severity messages — the ones that actually explain what went wrong. Future-you, debugging at 4:45 PM on a Friday, says thanks.

That’s the list. If one of these saves you an afternoon, it did its job. More GIS and Python how-tos in the Tech How-Tos section.