Select to view content in your preferred language

variable within a whereclause

2058
1
06-17-2013 02:36 PM
JamesArmstrong
Occasional Contributor
I am a novice with arcpy.

I would like to use the arcpy.Select_analysis to select a featureclass with a selection based on an attibute and a txtfile.
All is working except that the where clasue does not like it when I try to install a variable.  Such as:

arcpy.Select_analysis(fromFC, line[:-1]+"\\output_temp", exp)

the FromFC is the FC I am coping from.
the line[:-1]+"\\output_temp" is the FC I am pushing the selection of the FromFC to, ans
exp is the expression -  exp = '"SystemOwner" = \'Rockingham\''

Rockingham is in the place I would like to put the variable as I have several towns to run through.  I am not sure of the syntax by which to add the variable, as defined in an open statement for a textfile.

Any ideas or suggestions?
0 Kudos
1 Reply
MathewCoyle
Honored Contributor
You'd just need to use string substitution. Something like this.

exp = '"SystemOwner" = \'{0}\''.format(variable)
0 Kudos