select by attribute python script, greater than integer variable, cannot concatenate with string

730
1
04-18-2017 09:45 PM
MichaelFletcher1
New Contributor II

Hi Everyone, I am trying to write a query that selects by attribute, looping through different files, but have run into a snag because the variable is numeric and I wish to select values less than that number. If I convert the number to string, it is not a valid query. Code below:

while row:

FromVar = str(row.Fromage)

Fromcommand = "'" + "FROMAGE" + "<" + "FromVar" + "'"

print Fromcommand

row = rows.next()

arcpy.SelectLayerByAttribute_management("Multipoint Yellowstone plus a little Shatsky", "SUBSET_SELECTION", Fromcommand)

0 Kudos
1 Reply
DanPatterson_Retired
MVP Esteemed Contributor

"\"FROMAGE\" < {}".format(1) as in...

>>> for i in range(3):   print("\"FROMAGE\" < {}".format(i))
... 
"FROMAGE" < 0
"FROMAGE" < 1
"FROMAGE" < 2
 

the trick is in the escape encoding and the format formatter