<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Hatch expression help in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/hatch-expression-help/m-p/277668#M21423</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Square brackets work fine in the label expression (tested on 10.1)&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def FindLabel ( [FIELD_NAME] ):
&amp;nbsp;&amp;nbsp;&amp;nbsp; rs = [FIELD_NAME][-2:]
&amp;nbsp;&amp;nbsp;&amp;nbsp; ls = [FIELD_NAME][:-2]

&amp;nbsp;&amp;nbsp;&amp;nbsp; return&amp;nbsp; ls + "+" + rs&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You are indeed correct! &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think I must have been just testing that on single line ones like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;[FIELD_NAME][0:-2]&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;which do not work!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 13:31:03 GMT</pubDate>
    <dc:creator>StacyRendall1</dc:creator>
    <dc:date>2021-12-11T13:31:03Z</dc:date>
    <item>
      <title>Hatch expression help</title>
      <link>https://community.esri.com/t5/python-questions/hatch-expression-help/m-p/277664#M21419</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This is driving me crazy and I'm sure its something really simple but I can't find examples to show me what to do so I'm hoping someone here can help me out.&amp;nbsp; I have a route with measures that I'm trying to format into 123+45&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I ran this in PythonWin just to make sure I had this part right:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;station = "37000"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;rs = station[-2:]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ls = station[:-2]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print ls + "+" + rs&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;it gave me this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;370+00&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;just what I'm trying to do.&amp;nbsp; So then I go to the Hatch Text Expression dialogue and hit advanced.&amp;nbsp; First thing I probably need to know is what FindLabel is doing?&amp;nbsp; I looked around on the internet&amp;nbsp; trying to find it and still I'm not very sure.&amp;nbsp; Could be I just suck at the internet though.&amp;nbsp; I'm guessing the statement def FindLabel ( esri_measure) just lists the arguments you're going to use below it.&amp;nbsp; Does it make a string or is it a still a number?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So far in the advanced box I can get this much to work:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;def FindLabel ( esri__measure &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; return str(int(esri__measure))&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and it seems to return a value with no decimals just fine.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But when I start trying to add to that to get my 123+45 format it keeps giving me the error "No features found.&amp;nbsp; Could not verify expression."&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is going to have a lot to do with my inexperience using Python this way and my inexperience with Python in general I'm sure, but I haven't been able to find any good examples on the internet to help me puzzle this out or explain it to me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If someone could show me how to enter this into the advanced expression box or point me to some good examples so I can figure it out myself that would be great.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Aug 2013 20:32:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/hatch-expression-help/m-p/277664#M21419</guid>
      <dc:creator>BrettMorse</dc:creator>
      <dc:date>2013-08-12T20:32:57Z</dc:date>
    </item>
    <item>
      <title>Re: Hatch expression help</title>
      <link>https://community.esri.com/t5/python-questions/hatch-expression-help/m-p/277665#M21420</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have never used this tool before, but it appears that you can't use square brackets &lt;/SPAN&gt;&lt;STRONG&gt;within &lt;/STRONG&gt;&lt;SPAN&gt;the expression, as square brackets also define the fields being passed to the tool...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, when you are using something like &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;[-2:]&lt;/SPAN&gt;&lt;SPAN&gt; in the expression, it is looking for a field named -2:, which doesn't exist, and thus has no features.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hopefully someone from ESRI has a workaround or some help?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Aug 2013 23:05:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/hatch-expression-help/m-p/277665#M21420</guid>
      <dc:creator>StacyRendall1</dc:creator>
      <dc:date>2013-08-12T23:05:16Z</dc:date>
    </item>
    <item>
      <title>Re: Hatch expression help</title>
      <link>https://community.esri.com/t5/python-questions/hatch-expression-help/m-p/277666#M21421</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think I found something that might help, using string formats. More info &lt;/SPAN&gt;&lt;A href="http://docs.python.org/2/library/string.html#format-string-syntax" rel="nofollow noopener noreferrer" target="_blank"&gt;here&lt;/A&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It will only work as long as your field is &lt;/SPAN&gt;&lt;STRONG&gt;always &lt;/STRONG&gt;&lt;SPAN&gt;five characters long (the other method would have worked if shorter or longer too). Note that it is a one-liner, so you &lt;/SPAN&gt;&lt;STRONG&gt;do not need to check the advanced box&lt;/STRONG&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;"{0}{1}{2}+{3}{4}".format( *[esri__measure])&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The asterisk unpacks the string, so "37000" becomes like the tuple ('3', '7', '0', '0', '0'), and the numbers in the format string address elements of this tuple.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If the number of characters in the field changes you could use a conditional statement to check length (in which case you would have to check the advanced box):&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def FindLabel ( [esri__measure] ):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if len([esri__measure]) == 5:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return "{0}{1}{2}+{3}{4}".format( *[esri__measure])
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif len([esri__measure]) == 6:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return "{0}{1}{2}{3}+{4}{5}".format( *[esri__measure])
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return "UNKNOWN FIELD LENGTH"&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:30:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/hatch-expression-help/m-p/277666#M21421</guid>
      <dc:creator>StacyRendall1</dc:creator>
      <dc:date>2021-12-11T13:30:58Z</dc:date>
    </item>
    <item>
      <title>Re: Hatch expression help</title>
      <link>https://community.esri.com/t5/python-questions/hatch-expression-help/m-p/277667#M21422</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Square brackets work fine in the label expression (tested on 10.1)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def FindLabel ( [FIELD_NAME] ):
&amp;nbsp;&amp;nbsp;&amp;nbsp; rs = [FIELD_NAME][-2:]
&amp;nbsp;&amp;nbsp;&amp;nbsp; ls = [FIELD_NAME][:-2]

&amp;nbsp;&amp;nbsp;&amp;nbsp; return&amp;nbsp; ls + "+" + rs&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:31:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/hatch-expression-help/m-p/277667#M21422</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2021-12-11T13:31:01Z</dc:date>
    </item>
    <item>
      <title>Re: Hatch expression help</title>
      <link>https://community.esri.com/t5/python-questions/hatch-expression-help/m-p/277668#M21423</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Square brackets work fine in the label expression (tested on 10.1)&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def FindLabel ( [FIELD_NAME] ):
&amp;nbsp;&amp;nbsp;&amp;nbsp; rs = [FIELD_NAME][-2:]
&amp;nbsp;&amp;nbsp;&amp;nbsp; ls = [FIELD_NAME][:-2]

&amp;nbsp;&amp;nbsp;&amp;nbsp; return&amp;nbsp; ls + "+" + rs&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You are indeed correct! &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think I must have been just testing that on single line ones like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;[FIELD_NAME][0:-2]&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;which do not work!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:31:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/hatch-expression-help/m-p/277668#M21423</guid>
      <dc:creator>StacyRendall1</dc:creator>
      <dc:date>2021-12-11T13:31:03Z</dc:date>
    </item>
    <item>
      <title>Re: Hatch expression help</title>
      <link>https://community.esri.com/t5/python-questions/hatch-expression-help/m-p/277669#M21424</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Square brackets work fine in the label expression (tested on 10.1)&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def FindLabel ( [FIELD_NAME] ):
&amp;nbsp;&amp;nbsp;&amp;nbsp; rs = [FIELD_NAME][-2:]
&amp;nbsp;&amp;nbsp;&amp;nbsp; ls = [FIELD_NAME][:-2]

&amp;nbsp;&amp;nbsp;&amp;nbsp; return&amp;nbsp; ls + "+" + rs&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The code block, which is simply a python function that takes an input and returns an output, should use a Python variable -- not field names. (The insertion of the field value for [fieldname] only happens in the expression block.)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
Expression: FindLabel(![FIELDNAME]!)

Code:
def FindLabel(fn):
&amp;nbsp; rs = fn[:3] # first three chars
&amp;nbsp; ls = fn[3:]&amp;nbsp; # characters four-&amp;gt; end
&amp;nbsp; return "{0}+{1}".format(rs, ls)&amp;nbsp; 
 &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:31:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/hatch-expression-help/m-p/277669#M21424</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-11T13:31:06Z</dc:date>
    </item>
    <item>
      <title>Re: Hatch expression help</title>
      <link>https://community.esri.com/t5/python-questions/hatch-expression-help/m-p/277670#M21425</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Okay, so I've tried these suggestions.&amp;nbsp; I'm think the problem might be the esri__measure comes from the route and is assigned where ever the hatch mark falls or something because nothing is working here for me anyway.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried this one.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
def FindLabel ( esri__measure ):
&amp;nbsp; if len(str(int( esri__measure ))) == 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return "0+00"
&amp;nbsp; elif len(str(int( esri__measure ))) == 2:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return "0+{0}{1}".format( *esri__measure )
&amp;nbsp; elif len(str(int( esri__measure ))) == 3:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return "{0}+{1}{2}".format( *esri__measure )
&amp;nbsp; elif len(str(int( esri__measure ))) == 4:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return "{0}{1}+{2}{3}".format( *esri__measure )
&amp;nbsp; elif len(str(int( esri__measure))) == 5:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return "{0}{1}{2}+{3}{4}".format( *esri__measure )
&amp;nbsp; elif len(str(int( esri__measure ))) == 6:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return "{0}{1}{2}{3}+{4}{5}".format( *esri__measure )
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It verifies, but it returns nothing.&amp;nbsp; Just a blank.&amp;nbsp; I also tried it without the str(int part and got the same thing.&amp;nbsp; A blank when verified.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The brackets are to call a field name, problem is this isn't a field name.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried this next.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
def FindLabel ( esri__measure ):
&amp;nbsp; m = esri__measure
&amp;nbsp; return m
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And that works.&amp;nbsp; Returns my station just as if I hadn't changed anything.&amp;nbsp; I'm not worried about the integer anymore because my interval is set to 1000' so there is nothing on the end anyway.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So with that working I'm thinking I'm on to something so I try this next.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
def FindLabel ( esri__measure ):
&amp;nbsp; m = esri__measure
&amp;nbsp; ls = m[:-2]
&amp;nbsp; rs = m[-2:]
&amp;nbsp; return ls "+" rs
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When I verify this it throws up the error "No features found.&amp;nbsp; Could not verify expression."&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is the same bit I tried out in PythonWin making m an integer and a string and it worked both times.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Maybe someone sees something I'm not catching (don't know about) and can get this working for me please.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;By the way I'm using 10.1&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again for the help here!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I just tried that first code in PythonWin and changed return to print and added the else at the bottom in case it wouldn't print any of the if statements and I get nothing.&amp;nbsp; No errors or anything so I'll be trying to figure that out too.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Just tried this too:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
def FindLabel ( esri__measure ):
&amp;nbsp; rs = esri__measure[-2:]
&amp;nbsp; ls = esri__measure[:-2]
&amp;nbsp; return ls + "+" + rs
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Same error, "No features found.&amp;nbsp; Could not verify expression"&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:31:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/hatch-expression-help/m-p/277670#M21425</guid>
      <dc:creator>BrettMorse</dc:creator>
      <dc:date>2021-12-11T13:31:09Z</dc:date>
    </item>
    <item>
      <title>Re: Hatch expression help</title>
      <link>https://community.esri.com/t5/python-questions/hatch-expression-help/m-p/277671#M21426</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;OK, I finally found the Hatch Expression calculator. Previously I was testing on Label Expression/Display expression, assuming that they were the same thing.&lt;/SPAN&gt;&lt;STRONG&gt; They are not.&lt;/STRONG&gt;&lt;SPAN&gt; If it is any use to others: more information is shown below about locating the Hatch Expression tool and the testing that lead to finding the answer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In Hatch Expression, this seems to work (note that it is not advanced, so that box must be un-checked):&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;"{0}{1}{2}+{3}{4}".format( *str(esri__measure))&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As before, this will only work for inputs of length 5. If you want to condition test, this seems to work (is advanced, box must be checked):&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def FindLabel ( esri__measure):
&amp;nbsp; EM = str(esri__measure)
&amp;nbsp; if len(EM) == 5:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return "{0}{1}{2}+{3}{4}".format(*EM)
&amp;nbsp; elif len(EM) == 6:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return "{0}{1}{2}{3}+{4}{5}".format(*EM)
&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return "UNDEFINED INPUT"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Unfortunately it doesn't seem possible to have any square brackets anywhere within the statement (see below). If this was possible, something like the following would work for any length of input &amp;gt; 2:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def FindLabel (esri__measure):
&amp;nbsp; s = ''.join(['{%s}' % i for i in str(esri__measure)])
&amp;nbsp; return s[:-6] + '+' + s[-6:]&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;HR /&gt;[/HR]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For others reading this post: Hatch Expression is (only? - I can't find much info) a property of Network Analyst Routes. To find Hatch Expression: Solve an NA Route analysis, use &lt;/SPAN&gt;&lt;STRONG&gt;Layer Properties&lt;/STRONG&gt;&lt;SPAN&gt; on the Route, select &lt;/SPAN&gt;&lt;STRONG&gt;Hatches&lt;/STRONG&gt;&lt;SPAN&gt; tab, go to the &lt;/SPAN&gt;&lt;STRONG&gt;Hatch Def&lt;/STRONG&gt;&lt;SPAN&gt;, under labels tick&lt;/SPAN&gt;&lt;STRONG&gt; Label these hatches&lt;/STRONG&gt;&lt;SPAN&gt;, click &lt;/SPAN&gt;&lt;STRONG&gt;Label Settings&lt;/STRONG&gt;&lt;SPAN&gt;, select &lt;/SPAN&gt;&lt;STRONG&gt;Build a text expression&lt;/STRONG&gt;&lt;SPAN&gt; radio button, click the &lt;/SPAN&gt;&lt;STRONG&gt;Expression&lt;/STRONG&gt;&lt;SPAN&gt; button... Here is an image showing the steps, and initial state after setting to Python and checking the advanced option:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]26685[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Things that work (display an output after clicking Verify):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]Non-advanced (i.e. single line):&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;esri__measure&lt;/PRE&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;str(esri__measure)&lt;/PRE&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;'{0}'.format(esri__measure)&lt;/PRE&gt;&lt;SPAN&gt;[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]Advanced:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def FindLabel ( esri__measure):
&amp;nbsp; return esri__measure&lt;/PRE&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def FindLabel ( esri__measure):
&amp;nbsp; return str(esri__measure)&lt;/PRE&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def FindLabel ( esri__measure):
&amp;nbsp; EM = str(esri__measure)
&amp;nbsp; return EM&lt;/PRE&gt;&lt;SPAN&gt;[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Things that fail (display &lt;/SPAN&gt;&lt;STRONG&gt;No features found. Could not verify expression.&lt;/STRONG&gt;&lt;SPAN&gt; after clicking Verify):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]Non-advanced:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;str(esri__measure)[0]&lt;/PRE&gt;&lt;SPAN&gt;[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]Advanced:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def FindLabel ( esri__measure):
&amp;nbsp; EM = str(esri__measure)
&amp;nbsp; return EM[0] + EM[-1]&lt;/PRE&gt;&lt;SPAN&gt;[/INDENT]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:31:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/hatch-expression-help/m-p/277671#M21426</guid>
      <dc:creator>StacyRendall1</dc:creator>
      <dc:date>2021-12-11T13:31:12Z</dc:date>
    </item>
    <item>
      <title>Re: Hatch expression help</title>
      <link>https://community.esri.com/t5/python-questions/hatch-expression-help/m-p/277672#M21427</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;The code block, which is simply a python function that takes an input and returns an output, should use a Python variable -- not field names. (The insertion of the field value for [fieldname] only happens in the expression block.)&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
Expression: FindLabel(![FIELDNAME]!)

Code:
def FindLabel(fn):
&amp;nbsp; rs = fn[:3] # first three chars
&amp;nbsp; ls = fn[3:]&amp;nbsp; # characters four-&amp;gt; end
&amp;nbsp; return "{0}+{1}".format(rs, ls)&amp;nbsp; 
 &lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Curtis, I was talking about a Label/Display Expression (assuming that it was the same as a Hatch Expression). It seems to work different to normal code blocks. You can access it through: Layer Properties, Labels tab, Expression button. Here is an image showing it in action:[ATTACH=CONFIG]26680[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It turns out that Hatch Expression is different again. See my above post for more info.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:31:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/hatch-expression-help/m-p/277672#M21427</guid>
      <dc:creator>StacyRendall1</dc:creator>
      <dc:date>2021-12-11T13:31:15Z</dc:date>
    </item>
    <item>
      <title>Re: Hatch expression help</title>
      <link>https://community.esri.com/t5/python-questions/hatch-expression-help/m-p/277673#M21428</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;To get to the hatching you have to be using a route.&amp;nbsp; The esri__measure comes from that automatically and is not a field that requires the [].&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To get to the hatch just go to your route properties and it will be a tab at the top.&amp;nbsp; Under the Hatch Class in the box on the left there will be a Hatch Def(1) or however many you add.&amp;nbsp; If you click on the Hatch Def you will have options, one of which will be to label the hatches you have set up.&amp;nbsp; You can control the symbol here like normal.&amp;nbsp; You can then click the label settings in the label section and click the build a text expression bubble and then click the expression button.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Once you click the expression button the dialogue box looks the exactly the same except it says Hatch Text Expression at the top instead of&amp;nbsp; Label Expression.&amp;nbsp; This is why I assume they are the same, just in two different places.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I appreciate the help with this, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Aug 2013 20:51:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/hatch-expression-help/m-p/277673#M21428</guid>
      <dc:creator>BrettMorse</dc:creator>
      <dc:date>2013-08-13T20:51:43Z</dc:date>
    </item>
    <item>
      <title>Re: Hatch expression help</title>
      <link>https://community.esri.com/t5/python-questions/hatch-expression-help/m-p/277674#M21429</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;To get to the hatching you have to be using a route.&amp;nbsp; The esri__measure comes from that automatically and is not a field that requires the [].&lt;BR /&gt;&lt;BR /&gt;To get to the hatch just go to your route properties and it will be a tab at the top.&amp;nbsp; Under the Hatch Class in the box on the left there will be a Hatch Def(1) or however many you add.&amp;nbsp; If you click on the Hatch Def you will have options, one of which will be to label the hatches you have set up.&amp;nbsp; You can control the symbol here like normal.&amp;nbsp; You can then click the label settings in the label section and click the build a text expression bubble and then click the expression button.&lt;BR /&gt;&lt;BR /&gt;Once you click the expression button the dialogue box looks the exactly the same except it says Hatch Text Expression at the top instead of&amp;nbsp; Label Expression.&amp;nbsp; This is why I assume they are the same, just in two different places.&lt;BR /&gt;&lt;BR /&gt;I appreciate the help with this, &lt;BR /&gt;&lt;BR /&gt;Thanks&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;See answer above. Finally found Hatch Expression on my own so updated the previous post. Didn't see your post until I had finished editing...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Aug 2013 21:36:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/hatch-expression-help/m-p/277674#M21429</guid>
      <dc:creator>StacyRendall1</dc:creator>
      <dc:date>2013-08-13T21:36:11Z</dc:date>
    </item>
    <item>
      <title>Re: Hatch expression help</title>
      <link>https://community.esri.com/t5/python-questions/hatch-expression-help/m-p/277675#M21430</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;def FindLabel ( esri__measure ): &amp;nbsp; if len(str(int( esri__measure ))) == 0: &amp;nbsp;&amp;nbsp;&amp;nbsp; return "0+00" &amp;nbsp; elif len(str(int( esri__measure ))) == 2: &amp;nbsp;&amp;nbsp;&amp;nbsp; return "0+{0}{1}".format( *esri__measure ) &amp;nbsp; elif len(str(int( esri__measure ))) == 3: &amp;nbsp;&amp;nbsp;&amp;nbsp; return "{0}+{1}{2}".format( *esri__measure ) &amp;nbsp; elif len(str(int( esri__measure ))) == 4: &amp;nbsp;&amp;nbsp;&amp;nbsp; return "{0}{1}+{2}{3}".format( *esri__measure ) &amp;nbsp; elif len(str(int( esri__measure))) == 5: &amp;nbsp;&amp;nbsp;&amp;nbsp; return "{0}{1}{2}+{3}{4}".format( *esri__measure ) &amp;nbsp; elif len(str(int( esri__measure ))) == 6: &amp;nbsp;&amp;nbsp;&amp;nbsp; return "{0}{1}{2}{3}+{4}{5}".format( *esri__measure )&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;It verifies, but it returns nothing.&amp;nbsp; Just a blank.&amp;nbsp; I also tried it without the str(int part and got the same thing.&amp;nbsp; A blank when verified.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This fails because the asterisk (*) only works on certain iterables: strings, lists, tuples. A float (which esri__measure is) is not iterable. However, I am surprised it didn't throw a more useful error, like TypeError.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The other issues you discussed in the above-mentioned post appear to be related to having square brackets within the expression. I cannot get square brackets within the expression to work...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The code below is an adaptation of your code above, but includes the case where len == 1. My earlier answer didn't account for the fact that esri_measure is a floating point number, so will not work correctly. You should note that using int() on floats doesn't round as you might expect, so I use int(round(esri__measure)).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;def FindLabel (esri__measure): &amp;nbsp; EM = str(int(round(esri__measure))) &amp;nbsp; if len(EM) == 0: &amp;nbsp;&amp;nbsp;&amp;nbsp; return "0+00" &amp;nbsp; elif len(EM) == 1: &amp;nbsp;&amp;nbsp;&amp;nbsp; return "0+0{0}".format(*EM)&amp;nbsp;&amp;nbsp; &amp;nbsp; elif len(EM) == 2: &amp;nbsp;&amp;nbsp;&amp;nbsp; return "0+{0}{1}".format(*EM) &amp;nbsp; elif len(EM) == 3: &amp;nbsp;&amp;nbsp;&amp;nbsp; return "{0}+{1}{2}".format(*EM) &amp;nbsp; elif len(EM) == 4: &amp;nbsp;&amp;nbsp;&amp;nbsp; return "{0}{1}+{2}{3}".format(*EM) &amp;nbsp; elif len(EM) == 5: &amp;nbsp;&amp;nbsp;&amp;nbsp; return "{0}{1}{2}+{3}{4}".format(*EM) &amp;nbsp; elif len(EM) == 6: &amp;nbsp;&amp;nbsp;&amp;nbsp; return "{0}{1}{2}{3}+{4}{5}".format(*EM)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Aug 2013 21:50:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/hatch-expression-help/m-p/277675#M21430</guid>
      <dc:creator>StacyRendall1</dc:creator>
      <dc:date>2013-08-13T21:50:25Z</dc:date>
    </item>
    <item>
      <title>Re: Hatch expression help</title>
      <link>https://community.esri.com/t5/python-questions/hatch-expression-help/m-p/277676#M21431</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;The code block, which is simply a python function that takes an input and returns an output, should use a Python variable -- not field names. (The insertion of the field value for [fieldname] only happens in the expression block.)&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
Expression: FindLabel(![FIELDNAME]!)

Code:
def FindLabel(fn):
&amp;nbsp; rs = fn[:3] # first three chars
&amp;nbsp; ls = fn[3:]&amp;nbsp; # characters four-&amp;gt; end
&amp;nbsp; return "{0}+{1}".format(rs, ls)&amp;nbsp; 
 &lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;In 10.1 there's no separate expression and code blocks, just an expression block in which you write the label function (in the Advanced view). The function def and the function code accepts field names:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]26686[/ATTACH]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:31:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/hatch-expression-help/m-p/277676#M21431</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2021-12-11T13:31:18Z</dc:date>
    </item>
    <item>
      <title>Re: Hatch expression help</title>
      <link>https://community.esri.com/t5/python-questions/hatch-expression-help/m-p/277677#M21432</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you&amp;nbsp; StacyRendall!!!!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I was almost there, not sure what happened to the == 1 in that one block, I swear it was there before.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So the trick is to make the variable and do the rounding and integer business then get the length of that instead of trying to do it on every if statement, saving all that typing in the process haha.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm still pretty new to python, only on chapter 7 in my book and that was the first time using the .format and * so thanks for teaching me something new.&amp;nbsp; I'll get it all figured out eventually.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now I just have to figure out how to get them perpendicular to my line.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Oh, that worked if someone missed it.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Aug 2013 12:32:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/hatch-expression-help/m-p/277677#M21432</guid>
      <dc:creator>BrettMorse</dc:creator>
      <dc:date>2013-08-14T12:32:09Z</dc:date>
    </item>
    <item>
      <title>Re: Hatch expression help</title>
      <link>https://community.esri.com/t5/python-questions/hatch-expression-help/m-p/277678#M21433</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Thank you&amp;nbsp; StacyRendall!!!!&lt;BR /&gt;&lt;BR /&gt;I was almost there, not sure what happened to the == 1 in that one block, I swear it was there before.&lt;BR /&gt;&lt;BR /&gt;So the trick is to make the variable and do the rounding and integer business then get the length of that instead of trying to do it on every if statement, saving all that typing in the process haha.&lt;BR /&gt;&lt;BR /&gt;I'm still pretty new to python, only on chapter 7 in my book and that was the first time using the .format and * so thanks for teaching me something new.&amp;nbsp; I'll get it all figured out eventually.&lt;BR /&gt;&lt;BR /&gt;Thanks again!&lt;BR /&gt;&lt;BR /&gt;Now I just have to figure out how to get them perpendicular to my line.&lt;BR /&gt;&lt;BR /&gt;Oh, that worked if someone missed it.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Great! I had never used .format() until now either!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Stacy&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Aug 2013 20:33:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/hatch-expression-help/m-p/277678#M21433</guid>
      <dc:creator>StacyRendall1</dc:creator>
      <dc:date>2013-08-14T20:33:18Z</dc:date>
    </item>
    <item>
      <title>Re: Hatch expression help</title>
      <link>https://community.esri.com/t5/python-questions/hatch-expression-help/m-p/277679#M21434</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;How do I do this if I'm trying to add an integer to each hatching value (to match up mileposts which don't start at zero) and round to the nearest tenth? If I use a hatching label expression, it won't let me also select the precision value so I need to include what I want the label to be rounded to in the hatching label expression and I don't know enough python to do this. Also, I'm using a measured polyline with one record so I don't have any fields to base it off of...except esri_measure, I think. I'm new to using measured polylines..&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 May 2014 22:11:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/hatch-expression-help/m-p/277679#M21434</guid>
      <dc:creator>IvySchultz1</dc:creator>
      <dc:date>2014-05-13T22:11:22Z</dc:date>
    </item>
  </channel>
</rss>

