This question already has an answer here:

I am trying to write a python code for select analysis.

FIPS: column in feature nameofinputfeature whose values needs to be compared with OFIPS

OFIPS: variable whose value is known each time the code is run.

I am having a problem in syntax of the {where clause}

my code is:

arcpy.Select_analysis("nameofinputfeature", "C:\\a.shp", '"FIPS" = %OFIPS%')

marked as duplicate by KHibma, Knightshound, mgri, Evil Genius, Dan C Apr 26 '17 at 14:16

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    It looks like you're mixing modelbuilder (%OFIPS%) and arcpy. Are you saying your OFIPS is a variable that value comes from somewhere in say a loop? So it'll run multiple times and OFIPS value changes each time its run? – KHibma Apr 26 '17 at 13:34
  • Yes, the value of OFIPS changes each time the loop is run, but I cant make it run even with a variable whose value is known (with no loop) – pnkjmndhl Apr 26 '17 at 13:45
  • 3
    There are a lot of answers already in the previously mentioned gis.se post. However, simply change '"FIPS" = %OFIPS%' to '"FIPS" = {}'.format(OFIPS) (assuming OFIPS is a variable in your code) – KHibma Apr 26 '17 at 13:50

Browse other questions tagged or ask your own question.