Error migrating python label expression from Arcmap to Arc Pro

144
4
Jump to solution
10-27-2021 10:26 AM
JoanHickey
New Contributor II

I have a python label expression that works in arcmap, but when I try it in ArcPro, I get an AttributeError:  "NoneType' object has not attribute 'strip'.  I think this might happen because there are null values in my data (just a guess).  Here is the expression: 

def FindLabel ( [PAD_addr],[UnitsRes],[NumBldgs]):
S =[PAD_addr].strip()
i = S.find('(')
nres = long([UnitsRes])
nbldg = long([NumBldgs])
if i == -1:
tmp = S.replace('::','\n')
elif i > 0:
tmp = S[0:i]
if nbldg > 1:
tmp2 = ' on lot)'
else:
tmp2 = ')'
if nres == 0:
return tmp + '\n(no res units)'
elif nres == 1:
return tmp + '\n(' + str(nres) + ' res unit' + tmp2
else:
return tmp + '\n(' + str(nres) + ' res units' + tmp2

Any help would be appreciated.

 

0 Kudos
1 Solution

Accepted Solutions
JoeBorgione
MVP Esteemed Contributor

@JoanHickey - this is  a better solution for you.

can't wait to retire....

View solution in original post

0 Kudos
4 Replies
JoeBorgione
MVP Esteemed Contributor

Trap for null values and use a pass:

if <!field!> is null:
    pass
else:
   #do the rest of the mojo

(not tested...)

can't wait to retire....
0 Kudos
DanPatterson
MVP Esteemed Contributor

or query your data for null values, switch the selection, then use your function

Code formatting ... the Community Version - Esri Community 

to make code easier to read


... sort of retired...
JoeBorgione
MVP Esteemed Contributor

@JoanHickey - this is  a better solution for you.

can't wait to retire....

View solution in original post

0 Kudos
JoanHickey
New Contributor II

It was actually

if <!field!> == None:
pass

 

Thanks for the help.

Happy retirement!