1

I need to update a column of values such that empty fields are changed to the string "OFF_ROAD." I've looked up a plethora of examples, and this is what I'm trying to get to work, but when I run it, nothing happens to the input file-

import arcpy

from arcpy import env

env.overwriteOutput = True

arcpy.env.workspace = "F:/EMILY/TEST/GET_TYPE_TEST/"

infc = "SpJoinscript.shp"

cur = arcpy.UpdateCursor(infc) 

for row in cur:

if row.TYPE_1 == "":         
    row.TYPE_1 = "OFF_ROAD"      
cur.updateRow(row) 
del row

del cur

print "done mothaf"

what am I overlooking here???!!!

2 Answers 2

1

If the field is empty (or NULL), the thing to test is whether the field is None.

Try changing the if row.TYPE_1 == "": to if row.TYPE_1 is None:

0

I figured it out- I used a da.updateCursor with an SQL query- import arcpy

from arcpy import env
env.overwriteOutput = True

arcpy.env.workspace = "F:/EMILY/TEST/GET_TYPE_TEST/"


infc = "SpJoinscript.shp"

with arcpy.da.UpdateCursor(infc, "TYPE_1", "TYPE_1=''") as cursor:
    for row in cursor:
        row[0] = "OFF_ROAD"
        cursor.updateRow(row)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.