<?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: Slicing fields in arcpy.da.UpdateCursor in Python Snippets Questions</title>
    <link>https://community.esri.com/t5/python-snippets-questions/slicing-fields-in-arcpy-da-updatecursor/m-p/806607#M279</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The ol' none versus '' versus ' ' versus '&amp;nbsp; &amp;nbsp;'&amp;nbsp; issue....&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 23 May 2018 11:46:15 GMT</pubDate>
    <dc:creator>JoeBorgione</dc:creator>
    <dc:date>2018-05-23T11:46:15Z</dc:date>
    <item>
      <title>Slicing fields in arcpy.da.UpdateCursor</title>
      <link>https://community.esri.com/t5/python-snippets-questions/slicing-fields-in-arcpy-da-updatecursor/m-p/806604#M276</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to join multiple fields using an update cursor, I want to trim a filed to a specific length while the cursor iterates through and adds another field to the final string. I am working with a streets data set and will need to do this for streets that have no pre direction and streets that have a pre direction. I want to take only the first 5 character of the street name when there is no pre directions and the first 3 character when there is a pre direction.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I run this script (testing it only for streets with no pre direction)&amp;nbsp; I do not get any errors but nothing is updated in the feature class.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; import &lt;/SPAN&gt;arcpy

&amp;nbsp;&amp;nbsp;&amp;nbsp; fc = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;r'C:\Users\achapman\Documents\18_0157_Woodlands_TX\WOODLANDS_TX.gdb\WOODLANDS_CL_WGS84'
&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; pbid = [&lt;SPAN style="color: #008000; font-weight: bold;"&gt;'PRE_DIR'&lt;/SPAN&gt;, &lt;SPAN style="color: #008000; font-weight: bold;"&gt;'ST_NAME'&lt;/SPAN&gt;, &lt;SPAN style="color: #008000; font-weight: bold;"&gt;'ST_TYPE'&lt;/SPAN&gt;, &lt;SPAN style="color: #008000; font-weight: bold;"&gt;'pBID'&lt;/SPAN&gt;]

&lt;SPAN style="color: #000080; font-weight: bold;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; with &lt;/SPAN&gt;arcpy.da.UpdateCursor(fc,pbid) &lt;SPAN style="color: #000080; font-weight: bold;"&gt;as &lt;/SPAN&gt;pbid_cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #000080; font-weight: bold;"&gt;for &lt;/SPAN&gt;row &lt;SPAN style="color: #000080; font-weight: bold;"&gt;in &lt;/SPAN&gt;pbid_cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #000080; font-weight: bold;"&gt;if &lt;/SPAN&gt;(row [&lt;SPAN style="color: #0000ff;"&gt;0&lt;/SPAN&gt;] &lt;SPAN style="color: #000080; font-weight: bold;"&gt;is &lt;/SPAN&gt;&lt;SPAN style="color: #000080;"&gt;None&lt;/SPAN&gt;):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[&lt;SPAN style="color: #0000ff;"&gt;3&lt;/SPAN&gt;] = (row[&lt;SPAN style="color: #0000ff;"&gt;1&lt;/SPAN&gt;][:&lt;SPAN style="color: #0000ff;"&gt;5&lt;/SPAN&gt;]) + row[&lt;SPAN style="color: #0000ff;"&gt;2&lt;/SPAN&gt;]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pbid_cursor.updateRow(row)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 09:24:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/slicing-fields-in-arcpy-da-updatecursor/m-p/806604#M276</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-12T09:24:20Z</dc:date>
    </item>
    <item>
      <title>Re: Slicing fields in arcpy.da.UpdateCursor</title>
      <link>https://community.esri.com/t5/python-snippets-questions/slicing-fields-in-arcpy-da-updatecursor/m-p/806605#M277</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You might want to take out that space -&lt;/P&gt;&lt;PRE style="color: #000000; background-color: #ffffff; border: 0px; font-size: 9pt;"&gt;&lt;SPAN style="color: #000080; border: 0px; font-weight: bold; font-size: 12px;"&gt;if &lt;/SPAN&gt;(row [&lt;SPAN style="color: #0000ff; border: 0px; font-weight: inherit; font-size: 12px;"&gt;0&lt;/SPAN&gt;] &lt;SPAN style="color: #000080; border: 0px; font-weight: bold; font-size: 12px;"&gt;is &lt;/SPAN&gt;&lt;SPAN style="color: #000080; border: 0px; font-weight: inherit; font-size: 12px;"&gt;None&lt;/SPAN&gt;)&lt;/PRE&gt;&lt;P&gt;But what is the data type of "PRE_DIR". Are you sure it can be a None type?&lt;/P&gt;&lt;P&gt;Even an empty string like "" will make it True.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 May 2018 10:00:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/slicing-fields-in-arcpy-da-updatecursor/m-p/806605#M277</guid>
      <dc:creator>NeilAyres</dc:creator>
      <dc:date>2018-05-23T10:00:28Z</dc:date>
    </item>
    <item>
      <title>Re: Slicing fields in arcpy.da.UpdateCursor</title>
      <link>https://community.esri.com/t5/python-snippets-questions/slicing-fields-in-arcpy-da-updatecursor/m-p/806606#M278</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To follow on from Neil's comment, you have to check for what you think is None. like a space, an empty string, a real None and anything else you can think of.&lt;/P&gt;&lt;P&gt;Print statements would help if you are running this script stand-alone&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; row&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;None&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;""&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;" "&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&amp;nbsp; &lt;SPAN class="comment token"&gt;# check for None (aka &amp;lt;null&amp;gt;, empty string, space&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 May 2018 11:05:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/slicing-fields-in-arcpy-da-updatecursor/m-p/806606#M278</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2018-05-23T11:05:08Z</dc:date>
    </item>
    <item>
      <title>Re: Slicing fields in arcpy.da.UpdateCursor</title>
      <link>https://community.esri.com/t5/python-snippets-questions/slicing-fields-in-arcpy-da-updatecursor/m-p/806607#M279</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The ol' none versus '' versus ' ' versus '&amp;nbsp; &amp;nbsp;'&amp;nbsp; issue....&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 May 2018 11:46:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/slicing-fields-in-arcpy-da-updatecursor/m-p/806607#M279</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2018-05-23T11:46:15Z</dc:date>
    </item>
    <item>
      <title>Re: Slicing fields in arcpy.da.UpdateCursor</title>
      <link>https://community.esri.com/t5/python-snippets-questions/slicing-fields-in-arcpy-da-updatecursor/m-p/806608#M280</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;But there is only one None &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/wink.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 May 2018 11:57:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/slicing-fields-in-arcpy-da-updatecursor/m-p/806608#M280</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2018-05-23T11:57:30Z</dc:date>
    </item>
    <item>
      <title>Re: Slicing fields in arcpy.da.UpdateCursor</title>
      <link>https://community.esri.com/t5/python-snippets-questions/slicing-fields-in-arcpy-da-updatecursor/m-p/806609#M281</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Which is why I'm such a fan....&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 May 2018 12:02:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/slicing-fields-in-arcpy-da-updatecursor/m-p/806609#M281</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2018-05-23T12:02:45Z</dc:date>
    </item>
  </channel>
</rss>

