Error migrating python label expression from Arcmap to Arc Pro

686
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 Emeritus

@JoanHickey - this is  a better solution for you.

That should just about do it....

View solution in original post

0 Kudos
4 Replies
JoeBorgione
MVP Emeritus

Trap for null values and use a pass:

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

(not tested...)

That should just about do it....
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 Emeritus

@JoanHickey - this is  a better solution for you.

That should just about do it....
0 Kudos
JoanHickey
New Contributor II

It was actually

if <!field!> == None:
pass

 

Thanks for the help.

Happy retirement!