Skip to content

Instantly share code, notes, and snippets.

@mhweber
Created October 10, 2019 20:58
Show Gist options
  • Select an option

  • Save mhweber/d3aa0ba0b7619ad553d7b4aead7cb316 to your computer and use it in GitHub Desktop.

Select an option

Save mhweber/d3aa0ba0b7619ad553d7b4aead7cb316 to your computer and use it in GitHub Desktop.
Pass a variable to an arcpy selection query statement
import os, arcpy, sys
shp = 'F:/shapefile.shp'
arcpy.MakeFeatureLayer_management(shp,"lyr")
rows = arcpy.SearchCursor("lyr")
for row in rows:
name=str(row.getValue("ColumnName"))
arcpy.SelectLayerByAttribute_management("lyr", "NEW_SELECTION", "'ColumnName' = '%s'"%name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment