I've recently started learning Python and started using it to create label expressions in ArcMap. I ran into an error today that I can't figure out though (and seems like it should be simple). When I try to create the following expression:
def FindLabel ( [FacilityName] ):
S = [FacilityName]
S = S.upper()
return S
I get back an error as follows:
Error 0 on line 0.
Error running expression: FindLabel(ESRIExpressionArg0)
Traceback (most recent call last):
File "<expression>", line 1, in <module>
File "<string>", line 3, in FindLabel
AttributeError: 'NoneType' object has no attribute 'upper'.
[FacilityName] is a domained field, and Null values are allowed. I understand, I think, that 'NoneType' means that [FacilityName] is being given a None value before it's trying to be returned, but I don't know how to fix the problem.
Thanks,
Ethan
I'm pretty sure all the values get returned as strings, but in the case of a null value, it might be returned as None
, which would explain the error you're getting.
You can use a try..except
block or make a conditional statement inside your function to ignore None
values.
Here's with try..except
:
def FindLabel ( [FacilityName] ):
try:
S = [FacilityName]
S = S.upper()
return S
except AttributeError:
pass