Search Cursor

2921
31
Jump to solution
11-18-2016 12:05 PM
jaykapalczynski
Frequent Contributor

Trying to figure out what the class_field variable is in this query

  • fc is the Feature Class
  • Class_field is WHAT?
  • name_field is the field value?

import arcpy

fc = 'c:/base/data.gdb/roads'
class_field = 'Road Class'
name_field = 'Name'

# Create an expression with proper delimiters
expression = arcpy.AddFieldDelimiters(fc, name_field) + ' = 2'

# Create a search cursor using an SQL expression
with arcpy.da.SearchCursor(fc, [class_field, name_field],
                           where_clause=expression) as cursor:
    for row in cursor:
        # Print the name of the residential road
        print(row[1])
0 Kudos
31 Replies
DanPatterson_Retired
MVP Emeritus

u denotes unicode... you don't do anything about it

0 Kudos
curtvprice
MVP Esteemed Contributor

I moved the correct answer to Mitch Holley‌ who provided a link to the help, because I can. This very general question posed is well-answered by the Esri documentation in this case, and includes many useful examples.