Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Help with Expression Syntax with two variables - SelectLayerByAttribute.

$
0
0
I am trying to create and expression that uses the value of the ELEVATION field in a feature class to select out a single feature and export it to its own feature class; essentially "ELEVATION" = 3 where the value '3' is a variable.

Needless to say, I'm having difficulty with the expression--I don’t have a firm grasp on the whole "\"" thing.

Here's what I have at the moment.

Code:

field = "ELEVATION"
cursor = arcpy.SearchCursor(GAGELayer)
for row in cursor:
    ElValue = float(row.getValue(field))
    exp = "\"" + field + "\" = " + GridValue + ""\"
    arcpy.SelectLayerByAttribute_management (GAGEMergeLayer, "NEW_SELECTION", exp)

I get it if '3' was a constant. (I'm not real clear what "\"" means exactly. does "\"" = "" or = "? And how do you reverse it for the end of an expression?)

Something like this

Code:

exp = "\"" + field + "\" = 3"
I'm not sure how to take that and make the expression work with '3' as a variable.

Any help (and a little explanation) would be greatly appreciated.

Viewing all articles
Browse latest Browse all 2485

Trending Articles