0

I'm trying to do a loop for select and export layers by attribute and name them based on the field value. I've written the script below and it creates the shapefiles which picks up field values as shapefiles' name but they are empty output shapefiles. looks like the query in the select process isn't run.

arcpy.env.workspace = r'C:\temp'

# Create the search cursor
cursor = arcpy.SearchCursor('fc', '')

# Iterate through rows in cursor
for row in cursor:
    outfc=r'C:\temp\test'+"\\"+str("{0}".format(row.Project))
    arcpy.Select_analysis("fc",outfc,'"Project"=\'"{0}".format(row.Project)\'')

### Project is the field name which is a String.
2

it is easier to use the triple quote than to try mixing the different types of quotes. In your case the format statement is within the text string, so that it is interpreted as a string.

outfc=r'C:\temp\test'+"\\"+ row.Project

arcpy.Select_analysis(infc ,outfc,""" "Project"= '{0}' """.format(row.Project) )
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.