I have a shapefile which has an attribute year. I used to generally copy and paste these features in the dataframe and then using the definition query just show polygons which were established before that year.

I want to know how can I do it using python. Like if I can give the input feature class, add all the years I want the different shapefiles for and the workspace where it can create shapefile for the mentioned years with the right naming convention.

  • 1
    What is "the right naming convention"? What version of ArcGIS are you working with? Are you looking to implement this as a script tool, a standalone Python script, a Python add-in, etc.? How do you want the user to interact with the script or tool? What inputs are required, and what are the desired results given a set of inputs? Try to describe each of these requirements in as exact language as possible otherwise it is easy to misinterpret what you are trying to do.
    – blah238
    Dec 9, 2012 at 1:47

2 Answers 2


I believe this was 'cross-posted' on another site... and the problem was answered with code below. (guidance by Mathew Coyle and Dan Patterson)

import arcpy
# input fc
fc = "D:\\2010.shp"
# the yr 'breaks'...hard-coded as a Python list.
yrs = [1991,1992,1996,1998,1999,2000,2003,2004,2005,2006,2008,2010]
# initialize variable (part of SQL qry) to remove previous selections
subtract = ''
for yr in yrs:
     where = '"Year" <= ' + str(yr) + subtract
     subtract = ' AND "Year" > ' + str(yr)
     filename = str(yr) + '.shp'
     arcpy.FeatureClassToFeatureClass_conversion(fc, "D:\\test output", filename, where)

This can be accomplished using Select Layer by Attribute followed by Copy Features.

For a more tailored answer, please see my comments above.

  • Good answer. Using this methodology, you could also very easily script what your particular attribute queries are going to be, and then just run the Select Layer by Attribute tool iteratively over all of your predefined queries. Dec 9, 2012 at 4:03

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.