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???!!!

MaryBeth
3,71425 silver badges42 bronze badges
asked Apr 26, 2016 at 15:40

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:

answered Apr 26, 2016 at 16:01
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)
answered Apr 26, 2016 at 16:01

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.