In my program:
I am selecting only schools of the specified type based on the "FACILITY" field and creating new feature class of the result.
Deleting records from the resulting feature class from "Select" where the "Verified" field does not equal "Y" or "y" (I need to use: Update cursor and deleteRow method)
- For the records that do not equal "y" print the name of each deleted school
My code is not deleting the features that are not equal to "Y". And I am not sure how to print out the values that do not equal "Y".
Current error: Traceback (most recent call last): File "C:\Program Files (x86)\Wing IDE 101 4.1\src\debug\tserver_sandbox.py", line 26, in File "C:\Program Files (x86)\Wing IDE 101 4.1\src\debug\tserver_sandbox.py", line 19, in selectSchools TypeError: 'Row' object does not support indexing
import arcpy
work = arcpy.env.workspace = "c:\Scripts\Lab 6 Data"
sType = "JUNIOR HIGH"
outFile = "output.shp"
arcpy.env.overwriteOutput = True
def selectSchools(work,sType, outFile):
fc = "Schools.shp"
arcpy.MakeFeatureLayer_management(fc, "schoolslyr")
query = "\"FACILITY\" = '{0}'".format(sType)
arcpy.Select_analysis(fc, outFile, query)
arcpy.AddMessage("Select_Analysis layer tool completed!")
where_c = "\"VERIFIED\" = 'y%'"
update = arcpy.UpdateCursor(outFile)
row = update.next()
for row in update:
row.setValue(where_c)
updates.updateRow(row)
if (row[0].upper() != 'y'):
row.deleteRow(row)
print ("NAME")
row = update.next()
selectSchools(work,sType,outFile)
arcpy.da.UpdateCursor()
rather thanarcpy.UpdateCursor()
. See ArcGIS Desktop Help - Update Cursorif (row[0].upper() != 'y'):
block should be indented furtherif (row[0].upper() != 'y'):
will always result intrue
asy
is not uppercase