AnsweredAssumed Answered

Python - Select by attributes query issue

Question asked by matthewrusso on Feb 4, 2015
Latest reply on Feb 5, 2015 by blake.terhune
import arcpy
code = ["007","013","014","015","017","019","021","023","027","029","031","033","035","037","039","041","043","045","047","049","051","055","059","063","065",
cnty = ["Archuleta","Boulder","Broomfield","Chaffee","Cheyenne","Clear_Creek","Conejos","Costilla","Custer","Delta","Denver","Dolores","Douglas","Eagle","Elbert","El_Paso","Fremont","Garfield",
    arcpy.SelectLayerByAttribute_management("Colorado_Clip","NEW_SELECTION",""""COUNTY_CODE" = code[0]""")
    arcpy.CopyFeatures_management("Colorado_Clip","H:/GIS DATA/Data/Conflation/RPAM Data NAD83.gdb/Colorado/" + cnty[0],"#","0","0","0")
    arcpy.SelectLayerByAttribute_management('Colorado_Clip', "CLEAR_SELECTION")
    del cnty[0]
    del code[0]
    print cnty
    print code  
    print code[0] + " Failed"


Above is my simple script.

The goal is to loop through the items on the list, select attributees and create a new shapefile based on the name in the list, clear my selection, del that item from the list and move on to the next one.


Problem I am running into is in line 10 where the {where_clause} is.  The tool does not want to take a list item for the value (code[0]) is not acceptable.  Is there a way around this so i can use my list I don't want to have to type all of these out manually.


Orginially i wanted to split this file, but the size of the file prevents me from doing this.  I also have to do this for 8 more states.


Anyone have any ideas?