AnsweredAssumed Answered

How do I skip attributes that are null or blank?

Question asked by NEOMAPPER on Feb 26, 2019
Latest reply on Feb 26, 2019 by PYadav-esristaff

Is there a way to check if a field is blank or null and if it's not continue the script? I can't quite get the function to work unless I'm missing something. Thanks

 

 

 if row[0] != "": # if field is not blank or null then...

 

import sys
import os
import arcpy

sdeconnection = "Database Connections/SDE.sde"
fc = 'Database Connections/SDE.sde/NEO.SDE.Inspections/NEO.SDE.ACInspectionSites2019'
fields = ["INSPECTEDBY", "INSPECTIONSTATUS"]
try: 
    edit = arcpy.da.Editor(sdeconnection) 
    print "edit created" 
    edit.startEditing() 
    print "edit started" 
    edit.startOperation() 
    print "operation started" 
    # Perform edits
    with arcpy.da.UpdateCursor(fc, fields) as cursor:
        # For each row, evaluate the WELL_YIELD value (index position
        # of 0), and update WELL_CLASS (index position of 1)
        for row in cursor:
            if row[0] != "": # if field is not blank or null then...
                row[1] = "Completed Inspection"
                # Update the cursor with the updated list
                cursor.updateRow(row)
    edit.stopOperation() 
    print "operation stopped" 
    edit.stopEditing(True)  ## Stop the edit session with True to save the changes 
    print "edit stopped" 
except Exception as err: 
    print err 
    if 'edit' in locals(): 
        if edit.isEditing: 
            edit.stopOperation() 
            print "operation stopped in except" 
            edit.stopEditing(False)  ## Stop the edit session with False to abandon the changes 
            print "edit stopped in except" 
finally: 
    # Cleanup 
    arcpy.ClearWorkspaceCache_management() 

Outcomes