IF Statement and Update Cursor, Checking to see if text field is empty is not working

625
2
07-21-2011 10:12 AM
MichaelRivera
Occasional Contributor II
I'm using the following code:

cur=arcpy.UpdateCursor("parsolak.shp")

for row in cur:
    if row.PARCEL_NO == "":
        row.PARCEL_NO = "R-O-W"
        cur.updateRow(row)

del row,cur

I know the script is accessing the parsolak.shp shapefile because I see a lock on it.  The mission is if any polygons have nothing in the PARCEL_NO field to populate the field with "R-O-W".  When I reopen the shapefile, there are still 14,000+ records with nothing in the PARCEL_NO field.

Any help would be appreicated, thanks.
Tags (2)
0 Kudos
2 Replies
ChrisSnyder
Regular Contributor III
How about:

cur=arcpy.UpdateCursor("parsolak.shp")
for row in cur:
   if row.PARCEL_NO in ("", " ", None): #covers blank, one blank space, or Null
      row.PARCEL_NO = "R-O-W"
   cur.updateRow(row)
del row,cur



The PARCEL_NO field is a text field, correct?
0 Kudos
MichaelRivera
Occasional Contributor II
Yes PARCEL_NO is a string field.
Your script worked, much thanks 🙂
0 Kudos