Dissolve - python looping

1236
2
06-25-2014 12:17 PM
Naga_RaghuveerModala
New Contributor II
Hi All,

I started learning python coding recently. I have hundreds of shape files in a geodatabase. i am dissolving certain fields in each shapefile. For this i am writing a for loop so that it reads each shape file in the geodatabse, dissolves the identical fields and save them in a new geodatabase as a separate file. Can anyone help me to write the code so that each file is saved with different name. Here is the code i came up with.

# import system modules
import arcpy
from arcpy import env
import os

# Set environment settings
env.workspace = "C:/Users/raghuravi23/Desktop/New folder/test2.gdb"

# Set local variables
fcList = arcpy.ListFeatureClasses()

for fc in fcList:
    arcpy.Dissolve_management(fc, "C:/Users/raghuravi23/Desktop/New folder/Blocks.gdb", ["STATEFP10", "COUNTYFP10", "TRACTCE10", "BLKGRPCE10", "BLOCKCE10"],"[[Shape_Length,{sum},Shape_Area,{SUM}]]", "", "DISSOLVE_LINES")

Thank you very much
Tags (2)
0 Kudos
2 Replies
JakeSkinner
Esri Esteemed Contributor
Hi Naga,

You could add a variable at the end of the feature class name that increments for each feature class.  Ex:
x = 1

for fc in fcList:
    arcpy.Dissolve_management(fc, "C:/Users/raghuravi23/Desktop/New folder/Blocks.gdb/fc_" + str(x), ["STATEFP10", "COUNTYFP10", "TRACTCE10", "BLKGRPCE10", "BLOCKCE10"],"[[Shape_Length,{sum},Shape_Area,{SUM}]]", "", "DISSOLVE_LINES")
    x += 1
0 Kudos
Naga_RaghuveerModala
New Contributor II
Thank you Jake, Got it working
0 Kudos