Hi,
I got a sample script from an older post but I cannot get it working.
I'm trying to remove duplicate values within records in a FC.
For example, in the first row above, I need to get rid of one "63350" and one "70169" keeping the ";" as delimiters.
import arcpy
InputFC = r"H:\PROGRAMMES\10_OTHER_PROJECTS\24_ATTRIBUTION_CHECKS\From_RTJ.gdb\REFID_sample_1_1"
InputField = "REF_ID"
cursor = arcpy.da.UpdateCursor(InputFC, ["REF_ID"])
for row in cursor:
strList = row.Value(InputField).split("; ")
strSet = set(strList)
str = "; "
conStr = str.join(strSet)
row.setValue(InputField, conStr)
cur.updateRow(row)
del row
del cursor
I'm getting an error related to line 12: AttributeError: 'list' object has no attribute 'Value'
Any help would be greatly appreciated.
Thanks
Solved! Go to Solution.
I revisited the documentation, and you are correct, i.e., row.Value is incorrect. Correct syntax for the old cursors would involve getValue and setValue, not just Value. So it appears to be mixing syntax and using incorrect syntax.
strList = row[0].split("; ")
doesn't work? An not directly related example that splits on spaces IF the row isn't empty.
in_fc0 = r"Some_featureclass_in_a_spaceless_path"
cursor = arcpy.da.UpdateCursor(in_fc0, ["Text_1"])
for row in cursor:
if row[0] is not None:
strList = row[0].split(" ")
print(strList)
['C', 'not', 'null']
['C', 'not', 'null']
['E_no_space']
You are mixing the syntax between the legacy cursors and the newer Data Access cursors, that is why you are getting the specific error. Review UpdateCursor—Help | ArcGIS for Desktop for proper syntax.
Accessing data using cursors—ArcPy Get Started | ArcGIS Desktop
actually both are supported
import arcpy
cursor = arcpy.da.SearchCursor(fc, ['fieldA', 'fieldB'])
for row in cursor:
print(row)
#Search and update cursors also support with statements.
import arcpy
with arcpy.da.SearchCursor(fc, ['fieldA', 'fieldB']) as cursor:
for row in cursor:
print(row)
The issue wasn't about using the with, but how the OP was trying to retrieve values from the cursor:
cursor = arcpy.da.UpdateCursor(InputFC, ["REF_ID"]) # Created DA cursor
for row in cursor:
strList = row.Value(InputField).split("; ") # Used old cursor syntax
Ahhhh, that is so old, I just thought it was an error Relic of ArcMap?
I revisited the documentation, and you are correct, i.e., row.Value is incorrect. Correct syntax for the old cursors would involve getValue and setValue, not just Value. So it appears to be mixing syntax and using incorrect syntax.