Friday 28 September 2018

arcpy - Unsupported Operand Type for Field Query


Following on from Correct SQL expression for SelectbyAttribute Tool, I have my code:


import arcpy


plantFile = r"U:\Users\K\Plants.shp"
field = "UID"

arcpy.MakeFeatureLayer_management (plantFile, "plant_temp")
expression = round("UID" / 2, 0) <> "UID" / 2
arcpy.SelectLayerByAttribute_management("plant_temp", "NEW_SELECTION", expression)

I encounter -- TypeError: unsupported operand type(s) for /: 'str' and 'int'


"UID" is a long integer field, so I'm not understanding why this is happening. I've looked up methods for changing types for individual values, but not for an entire field. I will also be running this on over 20,000 records, so processing time is a concern.





EDIT I applied the suggested expression expression = '''round("UID" / 2, 0) <> "UID" / 2'''


which returned ExecuteError: ERROR 000358: Invalid expression




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...