Search Cursor

1667
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
1 Solution

Accepted Solutions
MitchHolley1
MVP Regular Contributor
31 Replies
jaykapalczynski
Frequent Contributor

would it be easier to have a Search Cursor and WHERE clause using sql_clause?

0 Kudos
jaykapalczynski
Frequent Contributor

I want to search a FC where 'Field1 = No' or 'Field2 = no'

0 Kudos
MitchHolley1
MVP Regular Contributor
jaykapalczynski
Frequent Contributor

yea thats where I got to example from...what the heck is class_field varaible?

0 Kudos
jaykapalczynski
Frequent Contributor

ooooh....I think its looking at 2 fields and not 1 is that right?

0 Kudos
MitchHolley1
MVP Regular Contributor

yes

0 Kudos
jaykapalczynski
Frequent Contributor

But what If I wanted classfield=Yes and name_field=No

0 Kudos
BlakeTerhune
MVP Regular Contributor

You need to keep reading the documentation for cursors. There's a where_clause parameter where you can specify that stuff when you create the cursor.

DanPatterson_Retired
MVP Esteemed Contributor

good to bookmark ... What is ArcPy?—Help | ArcGIS for Desktop ....