I have a geodatabase with many polyline feature classes all with different names. I would like to write a code in python ArcGIS 10.1 to use a geoprossing tool on all classes in the gdb. How would this be done?

Would the same logic work for a folder of shapefiles?

For this question lets say I want to use Create Random Points 500 metres apart on all polylines in this gdb.

import arcpy
from arcpy import env
arcpy.env.workspace = "E:\Example.gdb"

arcpy.CreateRandomPoints_Management (

I asked a similar question on Stack Overflow, except using VBA to loop through a folder of excel workbooks.



Try something like this:

import arcpy
from arcpy import env
env.workspace = "E:\Example.gdb"

# here you are creating a list of all features from your workspace
lst = arcpy.ListFeatureClasses("", "Polyline")

# and here you are looping
for featureClass in lst:
  • 2
    Don't use "list" as a variable name (i.e. list = arcpy.ListFeatureClasses("", "Polyline")). A list is a python built-in type.
    – user2856
    Apr 23 '14 at 3:08

I would simply set my workspace (arcpy.env.workspace = "NAME OF GDB HERE") and then list the Line feature classes into a python list (fcs = arcpy.ListFeatureClasses("","Polyline")). Then you can loop through them.

So same as other answer provided but with 1 minor difference - incorporating the Polyline option:

import arcpy
arcpy.env.workspace = "C:\Your.gdb"

# Create list of all polyline feature classes
fcs = arcpy.ListFeatureClasses("", "Polyline")

for fc in fcs:

Some documentation here:


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.