[GIS] Debugging arcpy.da.UpdateCursor where clause which gives RuntimeError: Cannot find field

arcgis-10.1arcpycursorruntimeerror

I'm trying to use UpdateCursor in arcpy, but the where clause I'm using seems to be causing trouble. However, when I open up the table in ArcMap and use Select By Attributes with the exact same clause that causes an error in the Python script, it works fine.

The name of a feature class and a dictionary containing strings is passed into a function with the following code:

rows = arcpy.da.UpdateCursor(featureClass, "{0} = {1}".format("PropCode", "'"+hotelDict["hotelId"]+"'"))
for row in rows:
    print "stuff" #I just wanted to see if it was making it here

I get the following error: RuntimeError: Cannot find field 'PropCode = 'FR066''

More info that may or may not be helpful: I'm using ArcGIS 10.1, the field that is being searched in contains text, and using arcpy.AddFiedlDelimiters(featureClass, "PropCode") instead of just "PropCode" did not fix the problem.

There are no results from Googling "RuntimeError: Cannot find field", and PropCode = 'FR066' is correct when using Select By Attributes in ArcMap, so I'm kind of stumped.

Best Answer

Using the API wrong. arcpy.da's second argument is a list of fields, not a where clause. Did you mean:

cursor = arcpy.da.UpdateCursor(featureClass,
                               ['*'],
                               "{0} = '{1}'".format("PropCode",       
                                                    hotelDict["hotelId"]))
Related Question