My Python script uses two feature classes in a file geodatabase in ArcGIS Pro. I select several polygons from the Parcels fc and start the script. The script copies the polygons to the Neighborhoods fc, merges them into one polygon (using Dissolve) and should copy the script parameter entries into several fields of the new Neighborhoods polygon. I have tried many variations on the syntax for the "where clause" in the ArcPy SelectLayerByAttribute function, but always get an Invalid Expression failure on line 41:
arcpy.SelectLayerByAttribute_management (fc_out, "NEW_SELECTION", whereclause)
Any help would be greatly appreciated.
Here is the code:
Solved! Go to Solution.
I am not sure if this is your only problem, but you need to wrap strings in single quotes, it is covered in the Building a query expression—Help | ArcGIS Desktop documentation. Try:
whereclause = "Neighborhoods_2016.NBHD_NAME = 'NEW NBHD'"
I am not sure if this is your only problem, but you need to wrap strings in single quotes, it is covered in the Building a query expression—Help | ArcGIS Desktop documentation. Try:
whereclause = "Neighborhoods_2016.NBHD_NAME = 'NEW NBHD'"
Thank you, you got it in one. I had to change one other bit of code:
row[0] = nbhdName.Title()
became
row[0] = nbhdName.title()
Everything works now. Thank you!