Problem with select by attributes

869
2
01-18-2014 09:48 AM
JoannaKIlian
New Contributor
I've got problem with python to use select by attributes to my layer called "World Cities". I type this script:

arcpy.SelectLayerByAttribute_management ("World Cities","NEW_SELECTION","CITY_NAME" = 'Abancay')

and  I see :
Runtime error SyntaxError: keyword can't be an expression (<string>, line 1)

When I'm trying this tool in arcgis not by python everything is ok, but in script I see this error. Please help!
Tags (2)
0 Kudos
2 Replies
DanPatterson_Retired
MVP Emeritus
it seems you answered your own question...do you want to share it?
0 Kudos
RichardFairhurst
MVP Honored Contributor
I've got problem with python to use select by attributes to my layer called "World Cities". I type this script:

arcpy.SelectLayerByAttribute_management ("World Cities","NEW_SELECTION","CITY_NAME" = 'Abancay')

and  I see :
Runtime error SyntaxError: keyword can't be an expression (<string>, line 1)

When I'm trying this tool in arcgis not by python everything is ok, but in script I see this error. Please help!


The expression part of your script is not enclosed in quotes properly.  I believe "CITY_NAME" = 'Abancay' has to be "\"CITY_NAME\" = 'Abancay'" or '"CITY_NAME" = \'Abancay\''

Try:

arcpy.SelectLayerByAttribute_management ("World Cities","NEW_SELECTION","\"CITY_NAME\" = 'Abancay'")

or:

arcpy.SelectLayerByAttribute_management ("World Cities","NEW_SELECTION",'"CITY_NAME" = \'Abancay\'')
0 Kudos