AnsweredAssumed Answered

How to correct SQL expression for Search Cursor in Arcpy

Question asked by fumani on Aug 14, 2015
Latest reply on Aug 17, 2015 by xander_bakker

I need to create a search cursor to print out the values in an attribute table for a school shapefile. I need to print out all the values that correspond to HIGH SCHOOL in the field FACILITY for the School shapefile. For some reason the search cursor won't work when I try to apply the sql expression but works without it. I don't want to print out all the values in that field just specific ones. Is there something wrong with my sql statement?

 

 

 

#import arcpy module

import arcpy

from arcpy import env

arcpy.env.overwriteOutput = True

# I am setting the work path

env = 'S:\\376\\Summer15-2\\ahutche1\\lab07_data\\SectionB\\'

#I will set the variable for the schools shapefile

schools = 'Schools'

#create search cursor to loop thru schools. use where clause to return schools

#that are high schools. Use loops

#print out all the highschool names

#print total no. of high school records

sr = arcpy.SpatialReference(4326)

#I will create a search cursor for the schools shapefile

field = "FACILITY"

exp1 = '"FACILITY" = "HIGH SCHOOL"'

cursor = arcpy.SearchCursor(env+schools+'.shp',exp1)

for row in cursor:

    print(row.getValue(field))

Outcomes