AnsweredAssumed Answered

how to update field with name of FC for list of FCs ?

Question asked by Gabino011 on Feb 10, 2015
Latest reply on Feb 11, 2015 by blake.terhune

Hi Everybody -

 

I am trying to fill in the attribute in a newly created field 'Particle', with the name of the FC, which will be changing for a list of FCs. I've tried using 'CalculateField', with which I get the error: 'NameError: name 'xy_1' is not defined', where 'xy_1' is the name of the FC going through the loop.

 

I've tried using 'UpdateCursor' and I get the error: "  'list' object has no attribute 'setValue'  ". 

 

This is the code I've written so far:

 

fieldName1 = "Particle"

fieldType1 = "TEXT"

fieldlength = 20

 

wildcard = ""

fctype = ""

 

try:

    fcList =  arcpy.ListFeatureClasses(wildcard, fctype)

    # print fcList2

    for fc in fcList:

        print fc

        arcpy.AddField_management(fc,fieldName1,fieldType1,"","",fieldlength,"","NULLABLE")

 

[with:]

        desc = arcpy.Describe(fc)

        val = desc.name

        print val

        arcpy.CalculateField_management(fc, fieldName1, val, "PYTHON_9.3")

 

[OR:]

##        curs =  arcpy.da.UpdateCursor(fc,fieldName1)

##        for row in curs:

##            desc = arcpy.Describe(fc)

##            val = desc.name

##            print val

##            row.setValue(fieldName1,val)

##        curs.updateRow(row)

##        del curs, row

Outcomes