All of the attempts below result in ERROR 000358: Invalid expression
Any ideas on what I am doing wrong? I am working within a File GDB and with polygons.
Attempt 1:
def SelectLayer(val):
print '"Att1 = ' + "'" + val + "'" + '"'
arcpy.SelectLayerByAttribute_management('Source_lyr',
'NEW_SELECTION',
'"Att1 = ' + "'" + val + "'" + '"')
SelectLayer('Red')
Attempt 2:
def SelectLayer(val):
where_clause = '"Att1 = ' + "'" + val + "'" + '"'
print where_clause
arcpy.SelectLayerByAttribute_management('Source_lyr',
'NEW_SELECTION',
where_clause)
SelectLayer('Red')
Attempt 3:
def SelectLayer(val):
print "\"Att1 = \'{0}\'\"".format(val)
arcpy.SelectLayerByAttribute_management('Source_lyr',
'NEW_SELECTION',
"\"Att1 = \'{0}\'\"".format(val))
SelectLayer('Red')
This line below was working without error before I put it into a function. This is what all of the attempts above, and the line below, produce: "Att1 = 'Red'"
arcpy.SelectLayerByAttribute_management('Source_lyr', 'NEW_SELECTION', "Att1 = 'Red'")