I need to only update the fields attributes that are blank or Null, there are some attributes in Feilda and I want to skip those but I am not sure how do to do that. I have the following.
with arcpy.da.UpdateCursor(fc,['Fielda','COUNT','Field1']) as cursor:
for row in cursor:
if row[0] not in (None, "", " "):
row[2] = ",".join(dict1[row[0]])
cursor.updateRow(row)
dict1
where is this defined?
still don't know where your dict1 is defined but this code will skip the rows with records
with arcpy.da.UpdateCursor(fc,['Fielda','COUNT','Field1']) as cursor:
for row in cursor:
if row[0] not in (None, "", " "):
row[2] = ",".join(dict1[row[0]])
cursor.updateRow(row)
else:
print("All good, nothing to do here")
Your conditional as written is testing if the Fielda is not null so its doing the opposite of what you are wanting to do.
just change your conditional:
if row[0] in [None, "", " "]:
or you can filter nulls in the where clause:
with arcpy.da.UpdateCursor(fc, ['Fielda', 'Field1'], 'Fielda IS NULL') as cursor:
for row in cursor:
row[1] = ",".join(dict1[row[0]])
...
I meant that I need to update Field1 and that Field1 has some attributes and also FieldA sometimes has attributes.
dict1 = dict()
with arcpy.da.SearchCursor(fc,['FieldA','COUNT','FieldB']) as cursor:
for row in cursor:
if row[0] not in (None, "", " "):
dict1.setdefault(row[0],[]).append(str(row[2]))
with arcpy.da.UpdateCursor(fc,['FieldA','COUNT','Field1']) as cursor:
for row in cursor:
if row[2] is None:
if row[0] not in (None, "", " "):
row[2] = ",".join(dict1[row[0]])
cursor.updateRow(row)