import arcpy, string, os, fileinput from arcpy import env env.workspace = "filepath/filepath.gdb" env.overwriteOutput = True fc = "FeatureClass" verification = arcpy.Exists (fc) print verification del verification arcpy.AddField_management (fc, "NewField", "TEXT", "", "", "", "", "", "", "") cursor = arcpy.da.UpdateCursor (fc, "NewField") for row in cursor: delimfield = arcpy.AddFieldDelimiters (fc, ["OldField"]) row[0] cursor.UpdateRow(row) del row del cursor
Runtime error Traceback (most recent call last): File "<string>", line 22, in <module> AttributeError: 'da.UpdateCursor' object has no attribute 'UpdateRow'
Solved! Go to Solution.
import arcpy from arcpy import env env.overwriteOutput = True env.workspace = "filepath/filepath.gdb" fc = "FeatureClass" fields = ('OldField', 'NewField') #Add the new field arcpy.AddField_management (fc, "NewField", "TEXT") # Create update cursor for feature class # with arcpy.da.UpdateCursor(fc, fields) as cursor: # For each row, read the OldField value (index position # of 0), and update NewField value (index position of 1) # for row in cursor: row[1] = row[0] # Update the cursor with the updated list # cursor.updateRow(row)
for row in cursor: row.setValue("NewField", row.getValue("OldField")) cursor.updateRow(row)
What I am attempting to do is create a copy of an attribute field in a feature class. I want the values of both fields to be exactly the same, but I want their titles to be different. I think I'm close but I am receiving errors, and cannot resolve them myself.
import arcpy, string, os, fileinput from arcpy import env env.workspace = "filepath/filepath.gdb" env.overwriteOutput = True fc = "FeatureClass" verification = arcpy.Exists (fc) print verification del verification arcpy.AddField_management (fc, "NewField", "TEXT", "", "", "", "", "", "", "") cursor = arcpy.da.UpdateCursor (fc, "NewField") for row in cursor: delimfield = arcpy.AddFieldDelimiters (fc, ["OldField"]) row[0] cursor.UpdateRow(row) del row del cursor
I think my issue is here: "delimfield = arcpy.AddFieldDelimiters (fc, ["OldField"])" I'm not even sure this is the right tool for copying over the values from one field to the other. After running the script I receive the error listed below. Any ideas?
Runtime error Traceback (most recent call last): File "<string>", line 22, in <module> AttributeError: 'da.UpdateCursor' object has no attribute 'UpdateRow'
import arcpy from arcpy import env env.overwriteOutput = True env.workspace = "filepath/filepath.gdb" fc = "FeatureClass" fields = ('OldField', 'NewField') #Add the new field arcpy.AddField_management (fc, "NewField", "TEXT") # Create update cursor for feature class # with arcpy.da.UpdateCursor(fc, fields) as cursor: # For each row, read the OldField value (index position # of 0), and update NewField value (index position of 1) # for row in cursor: row[1] = row[0] # Update the cursor with the updated list # cursor.updateRow(row)
import arcpy, string, os, fileinput from arcpy import env env.workspace = "filepath/file.gdb" env.overwriteOutput = True fc = "feature class" verification = arcpy.Exists (fc) print verification del verification arcpy.AddField_management (fc, "NewField", "TEXT", "", "", "", "", "", "", "") fields = ("OldField", "NewField") with arcpy.da.UpdateCursor (fc, fields) as cursor: for row in cursor: row[1] = row[0] cursor.updateRow(row) del row del cursor
with arcpy.da.UpdateCursor(fc, fields) as cursor: for row in cursor: row[1] = "test" cursor.updateRow(row)
So, something like this, but you have to test it yourself:import arcpy from arcpy import env env.overwriteOutput = True env.workspace = "filepath/filepath.gdb" fc = "FeatureClass" fields = ('OldField', 'NewField') #Add the new field arcpy.AddField_management (fc, "NewField", "TEXT") # Create update cursor for feature class # with arcpy.da.UpdateCursor(fc, fields) as cursor: # For each row, read the OldField value (index position # of 0), and update NewField value (index position of 1) # for row in cursor: row[1] = row[0] # Update the cursor with the updated list # cursor.updateRow(row)
PS - Incidentally, you may just have a case-sensitivity error in:
cursor.UpdateRow(row)
...since 'UpdateRow' is not recognized, you may fix your own error with 'updateRow'.
I just noticed that.