[GIS] Using Null values in Field Calculator

arcgis-desktoparcmapfield-calculatornullpython-parser

I have a python script in the field calculator that reads dates and populates a status field. When there is an empty value in the "actual" field, that is the status of the project. Here is the code that I use:

def cal(rec_a, soc_a, stk_a, plat_a, perm_a, per_a, status):

    if rec_a == " ":
      return "Field"

    elif soc_a == " ":
      return "Consult"

    elif stk_a == " ":
      return "Stake"

    elif plat_a == " ":
      return "Plat"

    elif perm_a == " ":
      return "Permit"

    elif per_a == " ":
      return "Waiting"

    elif (per_a is not None) or (per_a == " "):
      return "Permit Rec"

And the expression is:

cal (!Recon_act!, !SOcons_act!, !Stake_act!, !Plat_act!, !permit_act!, !PerRec_act!, !status!)

How do I use that same expression, but instead of reading empty fields it reads Null values?

if rec_a IsNull: ?

if rec_a == Null: ?

Best Answer

You can create a list and check if your value exists in that list. Place your possible Null/empty/spaced values into that list and check them all at once.

def findnulls(fieldname):
    if rec_a in [None, "", " "]:
        return "Field"

None is the python keyword for Null.

If you want to find Nulls separate to empty values, use is None

if rec_a is None:
    return "value is Null!"
elif rec_a == " ":
    return "value is single space!"
elif rec_a == "": 
    return "value is empty!"
Related Question