Hi,
I have a fields that is populated with correct values, <Null>, and whitespace/empty. The field is of text value with both numbers and letters in the correct values. I want to remove all of the whitespace/empty and replace them with <Null> instead. I am trying to do this with the field calculator and python.
My current prelogic statement is:
def makeNull(unitType):
if unitType == str():
return None
And the box below is:
makeNull( !UnitType!)
However when the field is calculated it turns all of the values to <Null> instead of just the whitespace/empty. Any Idea what I am doing wrong?
Solved! Go to Solution.
Maybe you only try evaluating empty strings.
def makeNull(unitType):
if unitType == "":
return None
else:
return unitType
Maybe you only try evaluating empty strings.
def makeNull(unitType):
if unitType == "":
return None
else:
return unitType
#---- snag the fat-fingered space placer ---
a = " "
a.strip() == ""
Out[9]: True
So the problem was I didn't have a else statement. I added in your else statement and it worked. Thanks.