Skip to main content
added 237 characters in body
Source Link
reevesii
  • 1.5k
  • 1
  • 12
  • 29

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'")

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')

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'")
added 33 characters in body
Source Link
reevesii
  • 1.5k
  • 1
  • 12
  • 29

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')

All of the attempts below result in ERROR 000358: Invalid expression Any ideas on what I am doing wrong?

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')

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')
Source Link
reevesii
  • 1.5k
  • 1
  • 12
  • 29

Where Clause in SelectLayerByAttribute function resulting in invalid expression

All of the attempts below result in ERROR 000358: Invalid expression Any ideas on what I am doing wrong?

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')