<?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: Arcpy-Check a row for hyphens in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-check-a-row-for-hyphens/m-p/178279#M13692</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is helpful generally, but the US address locator styles don't appear to recognize the hyphenated address prefixes.&amp;nbsp; These addresses are Canadian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 04 Mar 2016 19:46:04 GMT</pubDate>
    <dc:creator>DianneGray</dc:creator>
    <dc:date>2016-03-04T19:46:04Z</dc:date>
    <item>
      <title>Arcpy-Check a row for hyphens</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-check-a-row-for-hyphens/m-p/178271#M13684</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying to do something fairly simple with Python (ArcGIS 10.3): populate a field called StreetNum with street addresses taken from a field called StreetAddr.&amp;nbsp; However, some street addresses have a one-digit unit number surrounded by spaces before the unit number (e.g. 3 - 560 Main St) and I want only the street number to appear in the StreetNum field.&amp;nbsp; So in other words, I want to populate StreetNum based on criteria: if there is a hyphen present in the string for a particular row in StreetAddr, then calculate the StreetNum by skipping the first 4 values of StreetAddr; otherwise, use the values of StreetAddr the way they are.&lt;/P&gt;&lt;P&gt;I've tested the cases and they work.&amp;nbsp; However, I cannot come up with the proper criteria to check for a hyphen in a given row (no matter how I change my criteria, the script either passes or fails all rows).&amp;nbsp; How would I correctly word my loop criteria?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# Insert Search Cursor into StreetAddr field&lt;/P&gt;&lt;P&gt;rows = arcpy.SearchCursor(fc,["StreetAddr"])&lt;/P&gt;&lt;P&gt;# Check for hyphens in this field&lt;/P&gt;&lt;P&gt;for row in rows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if "-" in str(row):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Calculate the field by removing the unit number and hyphen from StreetAddr&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(in_table=fc, field="StreetNum", expression="Mid( [StreetAddr],5 )", expression_type="VB", code_block="")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Calculate the field by taking the content from StreetAddr&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(in_table=fc, field="StreetNum", expression="[StreetAddr]", expression_type="VB", code_block="")&lt;/P&gt;&lt;P&gt;del rows&lt;/P&gt;&lt;P&gt;del row&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Mar 2016 19:49:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-check-a-row-for-hyphens/m-p/178271#M13684</guid>
      <dc:creator>DianneGray</dc:creator>
      <dc:date>2016-03-03T19:49:49Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy-Check a row for hyphens</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-check-a-row-for-hyphens/m-p/178272#M13685</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Dianne,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can accomplish this using the Field Calculator.&amp;nbsp; Ex:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Pre-logic script code:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def calc(field1):
&amp;nbsp; if "-" in field1:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return field1.split(" ", 2)[-1]
&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return field1&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;StreetNum=&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;calc(!StreetAddr!)&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Be sure 'Python' is checked at the top of the field calculator:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Screen1.PNG" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/188653_Screen1.PNG" style="height: auto;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:08:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-check-a-row-for-hyphens/m-p/178272#M13685</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-11T09:08:55Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy-Check a row for hyphens</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-check-a-row-for-hyphens/m-p/178273#M13686</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jake,&lt;/P&gt;&lt;P&gt;Can you please explain the syntax of split?&amp;nbsp; What do the numbers 2 and -1 correspond to?&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried using that section of code, but Field Calculator ended up calculating all records to match StreetAddr (in other words, nothing passed the test).&amp;nbsp; Why would this be the case?&amp;nbsp; There are two records that have unit numbers, and all I want is the street numbers without the unit number (e.g. 7 - 364 Lougheed Rd should become 364 Lougheed Rd) (I realize my wording above might have been a bit confusing).&amp;nbsp; I know I could fix this manually but for acquiring more Python experience I'd like to know how to address this with Python.&amp;nbsp; What else could you suggest?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Mar 2016 22:15:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-check-a-row-for-hyphens/m-p/178273#M13686</guid>
      <dc:creator>DianneGray</dc:creator>
      <dc:date>2016-03-03T22:15:16Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy-Check a row for hyphens</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-check-a-row-for-hyphens/m-p/178274#M13687</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;if it were as simple as one case, why don't you examine the following conceptually&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; x&lt;/P&gt;&lt;P&gt;'3 - 560 Main St'&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; "- " in x&lt;/P&gt;&lt;P&gt;True&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; y = x.split("- ")[1]&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; y&lt;/P&gt;&lt;P&gt;'560 Main St'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note, I am checking for "dash space" not just "dash"&lt;/P&gt;&lt;P&gt;If found (True), then split on the aforementioned and take the first fiddly bit (counting from 0... ergo the last piece of the split&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Mar 2016 22:31:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-check-a-row-for-hyphens/m-p/178274#M13687</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-03-03T22:31:25Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy-Check a row for hyphens</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-check-a-row-for-hyphens/m-p/178275#M13688</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have you thought about using the &lt;A href="http://desktop.arcgis.com/en/arcmap/10.3/tools/geocoding-toolbox/standardize-addresses.htm" title="http://desktop.arcgis.com/en/arcmap/10.3/tools/geocoding-toolbox/standardize-addresses.htm"&gt;Standardize Addresses—Help | ArcGIS for Desktop&lt;/A&gt; tool and joining the table and calculating the desired results.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Mar 2016 01:30:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-check-a-row-for-hyphens/m-p/178275#M13688</guid>
      <dc:creator>WesMiller</dc:creator>
      <dc:date>2016-03-04T01:30:40Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy-Check a row for hyphens</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-check-a-row-for-hyphens/m-p/178276#M13689</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The split method will split the string on a space (" ").&amp;nbsp; The '2' in this syntax is telling the method to stop after the 2nd space is found.&amp;nbsp; For example, take the following address:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;7 - 364 Lougheed Rd&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I were to run the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;text = '7 - 364 Lougheed Rd'
print text.split(" ", 2)&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The following list would be returned:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;['7', '-', '364 Lougheed Rd']&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The '-1' in the syntax is going to return the last value in the list.&amp;nbsp; In this case, it will return '364 Lougheed Rd'.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want to upload a sample of the data, I could take a look at it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:08:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-check-a-row-for-hyphens/m-p/178276#M13689</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-11T09:08:58Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy-Check a row for hyphens</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-check-a-row-for-hyphens/m-p/178277#M13690</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I second Wes's comment, especially since the tool is available at all licensing levels.&amp;nbsp; There are also several Python-based packages that have similar functionality.&amp;nbsp; I personally like &lt;A href="https://github.com/datamade/usaddress"&gt;usaddress&lt;/A&gt;, but I only work with US addresses.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Mar 2016 15:11:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-check-a-row-for-hyphens/m-p/178277#M13690</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2016-03-04T15:11:39Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy-Check a row for hyphens</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-check-a-row-for-hyphens/m-p/178278#M13691</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;IMG alt="Kelowna Addresses.JPG" class="image-1 jive-image" src="/legacyfs/online/188831_Kelowna Addresses.JPG" style="height: auto;" /&gt;&lt;/P&gt;&lt;P&gt;So here are the addresses that get calculated into StreetNum directly from StreetAddr. No splitting was done for the hyphenated fields when I copied your above code as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="image-2 jive-image" src="https://community.esri.com/legacyfs/online/188832_pastedImage_1.png" style="max-width: 1200px; max-height: 900px;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Mar 2016 19:40:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-check-a-row-for-hyphens/m-p/178278#M13691</guid>
      <dc:creator>DianneGray</dc:creator>
      <dc:date>2016-03-04T19:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy-Check a row for hyphens</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-check-a-row-for-hyphens/m-p/178279#M13692</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is helpful generally, but the US address locator styles don't appear to recognize the hyphenated address prefixes.&amp;nbsp; These addresses are Canadian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Mar 2016 19:46:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-check-a-row-for-hyphens/m-p/178279#M13692</guid>
      <dc:creator>DianneGray</dc:creator>
      <dc:date>2016-03-04T19:46:04Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy-Check a row for hyphens</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-check-a-row-for-hyphens/m-p/178280#M13693</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In the last dialog box, where you have !StreetAddr!, you will need to call the function you created in the dialog box above.&amp;nbsp; You should have the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;calc(!StreetAddr!)&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Mar 2016 19:47:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-check-a-row-for-hyphens/m-p/178280#M13693</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2016-03-04T19:47:39Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy-Check a row for hyphens</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-check-a-row-for-hyphens/m-p/178281#M13694</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Oh wow, it worked!&amp;nbsp; That was easy! Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Mar 2016 19:57:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-check-a-row-for-hyphens/m-p/178281#M13694</guid>
      <dc:creator>DianneGray</dc:creator>
      <dc:date>2016-03-04T19:57:54Z</dc:date>
    </item>
  </channel>
</rss>

