Select to view content in your preferred language

Select Layer By Attribute in Python

11768
10
09-12-2016 07:22 AM
JohnWall
Occasional Contributor

I have the following code snippet:

arcpy.SelectLayerByAttribute_management("dissBuffs_lyr", "NEW_SELECTION", '[sumPoint_2] > 1')

Where dissBuffs_lyr is a layer which has been converted from a feature class stored within a File Geodatabase with a variety of attributes one of which is sumPoint_2. I've tried so many variations of '[sumPoint_2] > 1' that I'm running out of ideas does anyone have any idea what I might be doing wrong?

0 Kudos
10 Replies
AlexanderBrown5
Occasional Contributor II

Darren Wiens  Completely forgot about AddFieldDelimiters!  Thanks for mentioning.

John,

As Darren pointed out, you can just set your SQL expression, and reference as a variable in the SelectLayerByAttribute_management.

sql_exp = """{0} > {1}""".format(arcpy.AddFieldDelimiters(dissBuffs, "sumPoint_2"), int(1))‍
arcpy.SelectLayerByAttribute_management("dissBuffs_lyr", "NEW_SELECTION", sql_exp)‍‍

This would ensure that no matter where you pulled the data from, it would be formatted properly.