I have a shapefile with 100+ rows. What I like to do is to select each row and export all its data to a new shapefile. I tried using the arcpy.da.SearchCursor as follows:

with arcpy.da.SearchCursor(inputshape,"*",None) as cursor:
...     for row in cursor:
...         arcpy.FeatureClassToFeatureClass_conversion(row,pathToFolder,row[3] + ".shp")

Resulting in an error, arcpy displays following message:

Runtime error Traceback (most recent call last): File "", line 3, in File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\conversion.py", line 1694, in FeatureClassToFeatureClass raise e RuntimeError: Object: Error in executing tool

I think first parameter in the FeatureClassTofeatureClass_conversion method ist wrong. Other Examples show that there has to be the @Shape field. the workflow I would like to automate is very simple: 1) Open the attribute table 2) select a row 3) Export selected data to a new shapefile.


2 Answers 2


The cursor does not select anything, it is only returning a tuple (~a list of the attributes). But you can use the ObjectID returned by the cursor and pass this to Select:

Extracts features from an input feature class or input feature layer, typically using a select or Structured Query Language (SQL) expression and stores them in an output feature class.

Like this:

import arcpy,os


with arcpy.da.SearchCursor(input_fc,'OID@') as cursor:
    for row in cursor:
        sql="""{0} = {1}""".format(arcpy.AddFieldDelimiters(input_fc, arcpy.Describe(
        arcpy.Select_analysis(in_features=input_fc, out_feature_class=os.path.join(outfolder,'Shapefile_{0}.shp'.format(row[0])), 

enter image description here

But an easier option would be to use tool Split By Attributes with ObjectID field as split field:

Splits an input dataset by unique attributes.

  • Thank you so much! Your first provided option works brilliantly! Later on, I will have a look on your suggested second option!
    – Andi90
    Commented Oct 24, 2017 at 13:58

To export each row/feature within the cursor you will need to nest a variable expression that queries the active cursor row FID or some other unique identifier field/value. Then you may use the Select method using the active row expression aka where clause to export out the active row to a new fc.

The pseudo logic would go something like this:

with arcpy.da.SearchCursor(inputshape,'FID') as cursor:
    for row in cursor:
        where_clause = # define expression here for active field/row
        # Execute Select
        arcpy.Select_analysis(inputshape, out_feature_class, where_clause) # you'll have to define the out_feature_class
  • @Andi90 updated answer
    – artwork21
    Commented Oct 24, 2017 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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