1

I am creating a customized script tool that first clips out a line feature from one feature class, dissolves the fields of the clipped feature class so that just one feature is in it, appends the dissolved feature to another feature class, and then updates certain fields with default values for this newly appended feature.

When I run either of the codes below, no errors are thrown, and everything through the appending step works as expected (Note: 'NO_TEST' is passed for schema type with the result being that the appended feature is 'Null' for all fields.) However, I can't get the fields to update; they stay as 'Null' for all fields.

At first, I was including a where clause to instruct the tool to update only those rows with null values in the LOC_UNCERT field to prevent the tool from updating every row every time and instead just the newly added feature. In the properties of the tool, I set the default for the strSQL (where clause) to LOC_UNCERT IS NULL. The code for this attempt looked like the following (with adjusted sys.argv numbering due to leaving out the first 3 steps):

fcAppend = sys.argv[1]
strSQL = sys.argv[2]
lstFields = ["LOC_UNCERT", "CONC_FEAT_", "UH_EX"]
try:
    with arcpy.da.UpdateCursor(fcAppend, lstFields, strSQL) as cursor:
        for row in cursor:
            row[0] = "Linear"
            row[1] = "Point"
            row[2] = "N"
            cursor.updateRow(row)
except:
    print arcpy.GetMessages(2)

What I expected was that the LOC_UNCERT field would be updated to 'Linear', the CONC_FEAT_ field to 'Point', and the UH_EX field to 'N'. However, no fields are updated with this code.

So, I did some searching and saw this thread and tried taking out the where clause altogether and instead trying this:

fcAppend = sys.argv[1]
lstFields = ["LOC_UNCERT", "CONC_FEAT_", "UH_EX"]
try:
    with arcpy.da.UpdateCursor(fcAppend, lstFields) as cursor:
        for row in cursor:
            if row[0] == None:
                row[0] = "Linear"
                row[1] = "Point"
                row[2] = "N"
                cursor.updateRow(row)
except:
    print arcpy.GetMessages(2)

Again, I get no errors, but all fields are still blank after running this.

Here is an image of the resulting attribute table: enter image description here

I am using ArcMap 10.3.

2
with arcpy.da.UpdateCursor(fcAppend, lstFields) as cursor:
    for row in cursor:
        if row[0] == None:

To find Nulls in python you need to use is None (not == None).

See Null object in Python?

Null/None is not a value, so it can't be equal or not equal to anything.

  • Aha! Thank-you! I had tried 'IS NULL' but didn't think to use 'is' with 'None'. After the 24th attempt, it finally works! – Laura Jan 20 '16 at 16:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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