Python to Rename First Field In Table  - Gp.ListFields

Discussion created by mykonosman on Jan 10, 2012
Latest reply on Jan 13, 2012 by mykonosman
I am trying to create a Python script that will be able to rename the first field in a shape file by adding a new field, then calculating the new field to equal the first field.  The problem is that in each shape file, the first field will have a different name. I tried using a listfield to extract the name of the first field, but when I tried to calculate using it, the rows of the new field became populated with the name of the first field, not its value.


import arcgisscripting

# Create the geoprocessor object
gp = arcgisscripting.create(9.3)
gp.OverWriteOutput = True

# Set the workspace. List all of the folders within
gp.Workspace = "C:\ZP44"
fcs = gp.ListWorkspaces("*","Folder")

for fc in fcs:
    print fc
    gp.MakeFeatureLayer(fc + "\\Parcels.shp", "parcs") 
    fieldList = gp.ListFields("parcs")
    print fieldList[2].Name
    field1 = fieldList[2].Name
    gp.CalculateField_management("parcs", "Apn", "field1", "PYTHON", "")