Select to view content in your preferred language

Python Label Expression for Arc Map

1323
8
Jump to solution
07-27-2022 03:13 PM
by Anonymous User
Not applicable

First timer here, I am attempting to create a number of complex Label expressions in Arc Map. The problems is, how do you get a specific piece of a sting that is in a long text field. For example i am trying to say: if a field contains the string "ATM" then create a label "ATM. See below snippet. 

JeremiahMcDonald_0-1658959858309.png

No a simple DQ or Schema change will not work as I need to create labels based on all these categories and then push them to a SDE database ENV.  I am trying to improve my python ability. Please any help would be much appreciated. Thanks.  

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

def FindLabel ( [NOTES] 😞
if "ATM" in [NOTES]:
return "ATM"

 

This worked great! Thanks everyone. 

View solution in original post

0 Kudos
8 Replies
AdrianWelsh
MVP Honored Contributor

Maybe instead of the == in the operator, use "in".

This site has some info on using the "in" operator:

https://stackabuse.com/python-check-if-string-contains-substring/

 

DanPatterson
MVP Esteemed Contributor

split Notes by the commas to produce a list, trim the resultant strings if necessary and see if ATM is in the list

I don't have an IDE available, but

val_lst = [i.trim() for i in [Notes].split(",")]
if "ATM" in val_lst:
    ....

... sort of retired...
by Anonymous User
Not applicable

thank you, so are you trying to loop an array?

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

There is a Python str.find() method.

by Anonymous User
Not applicable

I will also give this a try. Have you ever tired using it in a Label expression? That is mostly where I am struggling. The expressions seems to behave different then a normal python IDE environment. Thank you so much for the help!

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

I understand what you mean about the different convention with field names having to be in brackets, but I re-tested using str.find() and it works as expected in a label expression.

by Anonymous User
Not applicable

Thank you so much can't wait to try it. 

0 Kudos
by Anonymous User
Not applicable

def FindLabel ( [NOTES] 😞
if "ATM" in [NOTES]:
return "ATM"

 

This worked great! Thanks everyone. 

0 Kudos