I have a polyline feature class with this attribute table:
I need to get values without decimal numbers.
I created a new field called "newLength" and tried to insert the new values (whole numbers only) with this code:
import arcpy
# add new field
arcpy.env.workspace = "G:\desktop\Project\lyr\New File Geodatabase.gdb"
arcpy.AddField_management("dis", "newLength", "LONG")
fc = r"G:\desktop\Project\lyr\New File Geodatabase.gdb\dis"
with arcpy.da.UpdateCursor(fc, "Shape_Length") as cursor: # second argument = field name
for row in cursor:
newValue = '%.0f' % float(str(row).strip('[]')) # convert list to string
# add the new numbers to the new field
with arcpy.da.UpdateCursor(fc, "newLength") as cursor: # second argument = field name
for row in cursor:
cursor.updateRow([newValue])
but the error is a new field with the same values in all rows:
whereas the second row is true and the first row is an error