Python equivalent to Modelbuilder Iterator (Iterate)

4966
1
09-15-2011 01:06 PM
DanielSheehan
New Contributor II
I often use iterate feature class and other iterations in modelbuilder. Can I replicate that easily in Python? It doesn't export the code so I have no template on how to create a .py script that does the same geoprocessing to every feature class in a feature dataset, for example.

I apologize if this was posted already but I could not find it using the Search Forums tool.

Thanks,
Danny
Tags (2)
0 Kudos
1 Reply
RaphaelR
Occasional Contributor II
hi danny,

you can easily iterate over a list of feature classes.
example from the arcgis 10 help(http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002z00000011000000):

import arcpy
from arcpy import env
import os

# Set the workspace for the ListFeatureClass function
#
env.workspace = "c:/base"

# Use the ListFeatureClasses function to return a list of 
#  all shapefiles.
#
fcList = arcpy.ListFeatureClasses()

# Copy shapefiles to a file geodatabase
#
for fc in fcList:
    arcpy.CopyFeatures_management(fc, "d:/base/output.gdb" + os.sep + fc.rstrip(".shp"))