Anyone know what on earth is wrong with this label expression code block? Once I get the error fixed, how on earth do I invoke it? ArcMAP had the pre logic script code bit separate from the expression, but now its not, how does it work now in Pro? (the help files seem to totally gloss it over)
Hi,
if needs == for equal in python.
Greetings Karsten
Your example doesn't look like valid Python?
Something like:
def FindLabel ( [UNIX Time] ):
if [UNIX Time] in ["TOM THUMB", "WILLIAM TELL"]:
return [UNIX Time]
else:
return [UNIX Time]
A single "=" in Python is very different from "==", which is what you want to do to check the value of a variable. You also need to give both conditions in full. Anything after the "OR" needs to evaluate to a boolean on its own.
def FindLabel ([NAME1]):
if [NAME1] == "TOM THUMB" OR [NAME1] == "WILLIAM TELL":
return [NAME1]
else:
return " "
Alternatively, you can check if the field is in a list of "match" values.
def FindLabel ([NAME1]):
if [NAME1] in ["TOM THUMB", "WILLIAM TELL"]:
return [NAME1]
else:
return " "
Please post code (and code block expressions) as formatted code not screenshots, makes it so much easier for people to read, copy, test and then hopefully answer.
https://community.esri.com/t5/python-blog/code-formatting-the-community-version/bc-p/1135971
!your_fld! if !your_fld! in ["Tom Thumb", "William Tell"] else " "
maybe?