Using Python to query a text string

1106
4
Jump to solution
03-02-2018 11:01 AM
AaronButterer
New Contributor II

I'm just getting started with Python and was following the example in: Using Feature Layers | ArcGIS for Developers 

I was able to follow the example but then I tried to manipulate it to use my data.  Everything was good until I got to the query.  I was able to query the numerical data fine but when I tried to pull a text value I couldn't make it work.

I tried a couple different ways but the one that seems to closest (to my admittedly untrained eye) is:

query_result1 = feature_layer.query(where='recordCulvertCorrect=' "no"',
out_fields='objectid,globalid,Date_,CulvertName,pullCulvertMaterial,pullCulvertDiameter')

My guess is it has to do with the way I am trying to work with the text string but I can't see to find what I'm looking for on line.  Any help is appreciated.

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor

Hi Aaron,

Try the following:

query_result1 = feature_layer.query(where="recordCulvertCorrect='no'",
out_fields='objectid,globalid,Date_,CulvertName,pullCulvertMaterial,pullCulvertDiameter')

View solution in original post

4 Replies
JakeSkinner
Esri Esteemed Contributor

Hi Aaron,

Try the following:

query_result1 = feature_layer.query(where="recordCulvertCorrect='no'",
out_fields='objectid,globalid,Date_,CulvertName,pullCulvertMaterial,pullCulvertDiameter')

JamesCrandall
MVP Frequent Contributor

Just a quick guess.

query_result1 = feature_layer.query(where="recordCulvertCorrect='no'", out_fields='objectid,globalid,Date_,CulvertName,pullCulvertMaterial,pullCulvertDiameter')
AaronButterer
New Contributor II

That did it.  Thanks!

0 Kudos
JoeBorgione
MVP Esteemed Contributor

A bit after the fact but something I like to do is create a where/select statement to a variable.  This approach I use a lot because I'm always plowing through a list in a for loop:

select = 'OBJECTID = {}'.format(street_name_list[i][0])
arcpy.SelectLayerByAttribute_management("view","ADD_TO_SELECTION",select)

So the variable 'select' is the 'where clause' in  select layer by attribute method:

SelectLayerByAttribute_management (in_layer_or_view, {selection_type}, {where_clause})
That should just about do it....
0 Kudos