I'm running an update cursor on an in_memory feature class to remove blank (but not null) values as part of a larger process.
I wanted by update cursor to loop through my list of fields and if the value was ''
or ' '
just replace it with a Null, however while it is finding the correct fields it's not updating the value.
If I explicitly refer to each item in the row e.g. row[1]
it works as expected, but not if I try to loop through row
.
This works:
with arcpy.da.UpdateCursor(AddressLayer, fieldList) as cursor:
for row in cursor:
arcpy.AddMessage(row)
u = 0
if i > 1000:
break
## THIS BIT DOESN'T WORK! ##
#for r in row:
# if r == '' or r == ' ':
# arcpy.AddMessage("OID = {}, value = '{}'".format(row[0], r))
# r = None
# u = 1
## THE ABOVE DOESN'T WORK! ##
## ADDED BECAUSE THE ABOVE DOESN'T WORK ##
r = 1
while r < 9:
if row[r] == '' or row[r] == ' ':
arcpy.AddMessage("OID = {}, value = '{}'".format(row[0], row[r]))
row[r] = None
u = 1
r+=1
## END OF ADDED BIT ##
if u == 1:
arcpy.AddMessage("Updating")
cursor.updateRow(row)
i+=1
But this (the commented section above) doesn't:
for r in row:
if r == '' or r == ' ':
arcpy.AddMessage("OID = {}, value = '{}'".format(row[0], r))
r = None
u = 1
What am I missing about the second code snippet that means it wouldn't work?