Creating a script to Calculate Field Python

502
3
Jump to solution
04-19-2022 12:28 PM
Labels (1)
RachaelMurtaugh
New Contributor III

I am trying to calculate a field based on whether another field is filled or null using python. I'm open to Arcade or SQL too. What I want to do is "If the Inspector field is filled, then calculate the Completed field as 'Flushed'. If the Inspector field is <Null>, then calculate the Completed field as 'Not Flushed'." Here is my code so far. The issue is that it is calculating everything as 'Flushed'.

def reclass(Inspector):

    if(Inspector=="Alan Covington" or "Braxton Lawrence" or "Dave Besler"):

        return "Flushed"

    else:

        return "Not Flushed"

0 Kudos
1 Solution

Accepted Solutions
Reinaldo_Cartagena
New Contributor III

#Another option:  This does work

def reclass(Inspector):

    if(Inspector == "Alan Covington" or Inspector =="Braxton Lawrence" or Inspector == "Dave Besler"):

        return "Flushed"

    else:

        return "Not Flushed"

View solution in original post

3 Replies
DanPatterson
MVP Esteemed Contributor

"in"

if(Inspector=="Alan Covington" or "Braxton Lawrence" or "Dave Besler"):

if(Inspector in ["Alan Covington", "Braxton Lawrence", "Dave Besler"]:

peeps = ["Alan Covington", "Braxton Lawrence", "Dave Besler"]

Inspector = "Dave Besler"

Inspector in peeps

True

... sort of retired...
0 Kudos
Reinaldo_Cartagena
New Contributor III

#Another option:  This does work

def reclass(Inspector):

    if(Inspector == "Alan Covington" or Inspector =="Braxton Lawrence" or Inspector == "Dave Besler"):

        return "Flushed"

    else:

        return "Not Flushed"

RachaelMurtaugh
New Contributor III

This worked. Oddly, the data was reading the field slightly differently when it came to the inspectors' names, and your addition helped. Thank you 

 

def reclass(Inspector):
if(Inspector=="Besler" or Inspector=="Covington" or Inspector=="Lawrence B"):
return "Flushed"
else:
return "Not Flushed"