Solved! Go to Solution.
This worked perfect, Thank you!
How can I get this to work for a numeric wildcard? I want to exclude from labeling all values of SITE that start with 18 so I put this together:
def FindLabel ( [SITE] 😞
if int([SITE]) == '18%':
return " "
else:
return [SITE]
The syntax checks out, but all the values that start with 18 are still labeled. If I take away the quotes around the 18 I get a syntax error. What gives? Is there no wildcard term for numbers in Python?
I think you are mixing two formats (VBscript and Python). The field SITE using the Python parser should be expressed as !SITE!.
You could use something like this with the Python parser:
def FindLabel(site):
return "" if str(site).startswith('18') == True else site
Your expression should be:
Findlabel(!SITE!)
I tested it with this:
def main():
tests = [18, 182, 1807, 18874, 1901, 17, 1981]
for test in tests:
print "in: {}, label:{}".format(test, FindLabel(test))
def FindLabel(site):
return "" if str(site).startswith('18') == True else site
if __name__ == '__main__':
main()
which resulted in:
in: 18, label:
in: 182, label:
in: 1807, label:
in: 18874, label:
in: 1901, label:1901
in: 17, label:17
in: 1981, label:1981
All values that start with 18 result in an empty string
Its weird how the in program label expression builder when set to Python still uses [XYZ] for the fields. (in ArcMap 10.3) Thanks, I wasn't aware of the startswith method, the code works now as:
def FindLabel ( [SITE] 😞
if str([SITE]).startswith('18') == True:
return " "
else:
return [SITE]