2

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: ?
  • It is None to be used, e.g. B!=None – FelixIP Sep 12 '16 at 20:04
  • if rec_a == None: – ziggy Sep 12 '16 at 20:07
  • 1
    you should learn how to use the arcpy.da.UpdateCursor and arcpy.da.InsertCursor cursors to update/add/insert rows and columns. its quicker and more intuitive than the clunky field calculator – ziggy Sep 12 '16 at 20:13
  • elif rec_a is None: gis.stackexchange.com/questions/78787/… – artwork21 Sep 12 '16 at 20:37
5

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

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.