Skip over or exclude empty variable in field calculator expression

1254
10
Jump to solution
05-07-2018 11:36 AM
ARCADMIN
New Contributor II

Hello, I am trying to parse street addresses using the field calculator and return just the street name.  My expression works except for addresses where there is only a house number with no street name after it; the calculation throws an error when it gets to these bad records where the street name doesn't exist.  I would like to be able to skip over these bad addresses and just return the input string for them.  I have tried adding a second condition to my if statement, but cannot seem to get the syntax correct.  Essentially what I want to say is "if the house number is a digit and the street name is not blank, return the street name otherwise return the full input string"

def addressParser(inString):
    splitString = inString.split(' ',1)
    houseNumber = splitString[0]
    streetName = splitString[1]
    if houseNumber.isdigit() and if streetName != "":
        return streetName
    else:
        return inString

addressParser( !FULLADDRESS! )

Thanks in advance for any help

0 Kudos
10 Replies
DanPatterson_Retired
MVP Emeritus

Joe... FIF ...(For the Future) You can pip install in the anaconda distribution for work in PRO if it supports python 3.6....