<?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: Use split field to update a new field in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/use-split-field-to-update-a-new-field/m-p/593304#M46490</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;what version of arcmap?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;is the destination field a text field?&amp;nbsp; It should be since splitting a strings results in string, if you want numbers, then you need to "int" the resultant split if placing in a short or long numeric field&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 28 Apr 2011 12:54:40 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2011-04-28T12:54:40Z</dc:date>
    <item>
      <title>Use split field to update a new field</title>
      <link>https://community.esri.com/t5/python-questions/use-split-field-to-update-a-new-field/m-p/593303#M46489</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi all,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am having problems with what should be something really simple.&amp;nbsp; I have a text field ("Start_Time") formatted as 11:23:40:60.&amp;nbsp; I am trying to split the text at ':' and write the first set to a new "Hour" field.&amp;nbsp; I can get the split to work but am having problems getting it into the "Hour" field.&amp;nbsp; I've tried it a couple of different ways and neither of them are working.&amp;nbsp; I've tried:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; UpCur = gp.UpdateCursor(InFC)
&amp;nbsp;&amp;nbsp;&amp;nbsp; row = UpCur.Next()
&amp;nbsp;&amp;nbsp;&amp;nbsp; while row:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TimeList = row.Start_Time.split(":")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hr = TimeList[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setvalue("Hour", hr)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row = UpCur.next()&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;SPAN&gt;and I've also tried:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; UpCur = gp.UpdateCursor(InFC)
&amp;nbsp;&amp;nbsp;&amp;nbsp; row = UpCur.Next()
&amp;nbsp;&amp;nbsp;&amp;nbsp; while row:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.Hour = row.Start_Time.split(":")[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row = UpCur.next()&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I must be missing something simple but can't figure it out.&amp;nbsp; I'm using ArcMap 9.3.1 and python 2.5.&amp;nbsp; Thanks in advance.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Stu&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Apr 2011 12:31:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-split-field-to-update-a-new-field/m-p/593303#M46489</guid>
      <dc:creator>StuartGibson</dc:creator>
      <dc:date>2011-04-28T12:31:07Z</dc:date>
    </item>
    <item>
      <title>Re: Use split field to update a new field</title>
      <link>https://community.esri.com/t5/python-questions/use-split-field-to-update-a-new-field/m-p/593304#M46490</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;what version of arcmap?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;is the destination field a text field?&amp;nbsp; It should be since splitting a strings results in string, if you want numbers, then you need to "int" the resultant split if placing in a short or long numeric field&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Apr 2011 12:54:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-split-field-to-update-a-new-field/m-p/593304#M46490</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2011-04-28T12:54:40Z</dc:date>
    </item>
    <item>
      <title>Re: Use split field to update a new field</title>
      <link>https://community.esri.com/t5/python-questions/use-split-field-to-update-a-new-field/m-p/593305#M46491</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Here is an example on how to do this.&amp;nbsp; You will need to replace 'arcpy' with 'gp'.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;input = "&amp;lt;table/feature class&amp;gt;"

rows = arcpy.SearchCursor(input)

for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; TimeList = row.Start_Time.split(":")
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows2 = arcpy.UpdateCursor(input)
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row2 in rows2:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row2.Hour = TimeList[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows2.updateRow(row2)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The field 'Hour' is of type Text.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:28:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-split-field-to-update-a-new-field/m-p/593305#M46491</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-12T01:28:36Z</dc:date>
    </item>
    <item>
      <title>Re: Use split field to update a new field</title>
      <link>https://community.esri.com/t5/python-questions/use-split-field-to-update-a-new-field/m-p/593306#M46492</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Here is the code I got to work at 10.&amp;nbsp; You should be able to replace 'arcpy' with 'gp' and this should work at 9.3.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;input = "&amp;lt;table/feature class&amp;gt;"

rows = arcpy.UpdateCursor(input)
for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; TimeList = row.Start_Time.split(":")
&amp;nbsp;&amp;nbsp;&amp;nbsp; row.Hour = TimeList[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)

del row, rows&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:28:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-split-field-to-update-a-new-field/m-p/593306#M46492</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-12T01:28:39Z</dc:date>
    </item>
    <item>
      <title>Re: Use split field to update a new field</title>
      <link>https://community.esri.com/t5/python-questions/use-split-field-to-update-a-new-field/m-p/593307#M46493</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm using ArcMap 9.3.1 (build 3500).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I originally had the "Hour" field as an interger and tried to using &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt; row.Hour = int(row.Start_Time.split(":")[0])&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;but when that wasn't working, I deleted the "Hour" field and recreated it as a text field just to try and get something working.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Apr 2011 14:13:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-split-field-to-update-a-new-field/m-p/593307#M46493</guid>
      <dc:creator>StuartGibson</dc:creator>
      <dc:date>2011-04-28T14:13:11Z</dc:date>
    </item>
    <item>
      <title>Re: Use split field to update a new field</title>
      <link>https://community.esri.com/t5/python-questions/use-split-field-to-update-a-new-field/m-p/593308#M46494</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Here is the code I got to work at 10.&amp;nbsp; You should be able to replace 'arcpy' with 'gp' and this should work at 9.3.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I get this error when running it after switching out for gp:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "C:/Temp/ESRI_Temp/Development/time_search2.py", line 12, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;TypeError: 'geoprocessing cursor object' object is not iterable&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcgisscripting
import string
gp = arcgisscripting.create(9.3)

inFC = "C:\\Temp\\ESRI_Temp\\Development\\sk_TEST.shp"

rows = gp.UpdateCursor(inFC)
for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; TimeList = row.Start_Time.split(":")
&amp;nbsp;&amp;nbsp;&amp;nbsp; row.Hour = TimeList[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)
del row, rows
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:28:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-split-field-to-update-a-new-field/m-p/593308#M46494</guid>
      <dc:creator>StuartGibson</dc:creator>
      <dc:date>2021-12-12T01:28:41Z</dc:date>
    </item>
    <item>
      <title>Re: Use split field to update a new field</title>
      <link>https://community.esri.com/t5/python-questions/use-split-field-to-update-a-new-field/m-p/593309#M46495</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try the following:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcgisscripting
gp = arcgisscripting.create(9.3)

input = "&amp;lt;shapefile&amp;gt;"

rows = gp.UpdateCursor(input)
row = rows.Next()
while row:
&amp;nbsp;&amp;nbsp;&amp;nbsp; TimeList = row.Start_Time.split(":")
&amp;nbsp;&amp;nbsp;&amp;nbsp; row.Hour = TimeList[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.UpdateRow(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp; row = rows.Next()

del row, rows&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:28:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-split-field-to-update-a-new-field/m-p/593309#M46495</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-12T01:28:44Z</dc:date>
    </item>
    <item>
      <title>Re: Use split field to update a new field</title>
      <link>https://community.esri.com/t5/python-questions/use-split-field-to-update-a-new-field/m-p/593310#M46496</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Try the following:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcgisscripting
gp = arcgisscripting.create(9.3)

input = "&amp;lt;shapefile&amp;gt;"

rows = gp.UpdateCursor(input)
row = rows.Next()
while row:
&amp;nbsp;&amp;nbsp;&amp;nbsp; TimeList = row.Start_Time.split(":")
&amp;nbsp;&amp;nbsp;&amp;nbsp; row.Hour = TimeList[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.UpdateRow(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp; row = rows.Next()

del row, rows&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;That works.&amp;nbsp; Thanks everyone for the help!!!&amp;nbsp; Is there a specific reason why the other methods weren't working?&amp;nbsp; I'm still a relative newbie with this, and am trying to understand why this worked and the other 'while' and 'for' loops didn't.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Stu&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:28:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-split-field-to-update-a-new-field/m-p/593310#M46496</guid>
      <dc:creator>StuartGibson</dc:creator>
      <dc:date>2021-12-12T01:28:46Z</dc:date>
    </item>
  </channel>
</rss>

