delete field o preserve field with python

Discussion created by acoana on Oct 31, 2010
Hi, I have many shapefiles where I execute MERGE, then I need to delete some fields manually because depending on the group of shapefiles I Merge, fields are different. I try to automate this task using python but I´m very new with development languages and only I rich to print field selected. using a willcard. Really, I would prefer to preserve 3 fields that are identical for all shapefiles, than waisting time deleting 25 o 30 fields that change depending on the source shapefiles I use in the Merge task.

I will appreciate any help on this.

Here is my modest python code that I try to use:



# Import the arcgisscripting module.
import arcgisscripting

# Create a variable to access the arcgisscripting/GpDispatch (Geoprocessor) object
gp = arcgisscripting.create()

# Set the workspace
gp.workspace = "D:\Modelodedatos_Milles\Hojas_25mil\Folder_pruebas"

fc = "Hidrografia_poligono.shp"

# Use the ListFields method on arcgisscripting/GpDispatch to return all the fields from a feature class
fields = gp.ListFields(fc, "TIPO*")

# Grab the first field from the list of fields
field = fields.Next()

# Loop through all the fields and print out the name
while field:
    print field.Name
    #gp.DeleteField(fc,field.Name)  -----Here is my problem
    field = fields.Next()