<?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: Need Python Example: sort rows, subtract current from next, load in new field in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329397#M25618</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Oops - in my example I never gave it any commands for what to do if it was the first time around the loop, so the counter stayed at 0 and never got into the update part. Here's what it should be (you could also add an updateRow to the else part if you want the very first row to have a value - this way it will just be skipped over).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if count != 0: # if this isn't the first time in the loop (ie. if you have a number to subtract)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count = count + 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.blankcolumnname = row.MEAS - previous # make the blank column = current - previous
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row) # updates the whole row, now with a value for the blank column
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; previous = row.MEAS # sticks the current value into the previous variable for the next time through the loop
&amp;nbsp;&amp;nbsp;&amp;nbsp; else: # do this if it is the first time in the loop
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count = 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; previous = row.MEAS
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 15:36:20 GMT</pubDate>
    <dc:creator>DarrenWiens2</dc:creator>
    <dc:date>2021-12-11T15:36:20Z</dc:date>
    <item>
      <title>Need Python Example: sort rows, subtract current from next, load in new field</title>
      <link>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329388#M25609</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Please help! I am new to Python. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I created a model in ModelBuilder. The last steps are to grab the attribute table of the feature class, sort MEAS column in ascending order and then subtract next value from current and load those values in the new field. (I have an empty field in the attribute table). &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I wrote a simple script, but all I could do is to sort the MEAS column and print values out. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Could anybody be so kind and get me an example code?....&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Apr 2011 13:18:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329388#M25609</guid>
      <dc:creator>NatalieLepsky</dc:creator>
      <dc:date>2011-04-21T13:18:28Z</dc:date>
    </item>
    <item>
      <title>Re: Need Python Example: sort rows, subtract current from next, load in new field</title>
      <link>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329389#M25610</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You should use an &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v0000003m000000.htm"&gt;UpdateCursor&lt;/A&gt;&lt;SPAN&gt; (there's an example). In the UpdateCursor statement, you specify which fields to sort. Then you loop through all your rows, each time sticking the current value into a variable to save it for the next row where you update the empty column with that value.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Apr 2011 13:59:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329389#M25610</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2011-04-21T13:59:34Z</dc:date>
    </item>
    <item>
      <title>Re: Need Python Example: sort rows, subtract current from next, load in new field</title>
      <link>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329390#M25611</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for your reply! I created a new dataset with sorted rows using a simple script. But still have problems with UpdateCursor. I try to retain the current value, but nothing works. Do you have a similar looping example?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Apr 2011 14:18:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329390#M25611</guid>
      <dc:creator>NatalieLepsky</dc:creator>
      <dc:date>2011-04-21T14:18:06Z</dc:date>
    </item>
    <item>
      <title>Re: Need Python Example: sort rows, subtract current from next, load in new field</title>
      <link>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329391#M25612</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;put the value into a variable for later use.&amp;nbsp; i.e. air code below&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
firstTime = True
for row in rows:
&amp;nbsp;&amp;nbsp; if firstTime:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myMeas = row.getValue('MEAS') #in your first iteration you will not have anything to update you just need to get the value for the next iteration
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; firstTime = False
&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue('MEASCalc', row.getValue('MEAS') - myMeas
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myMeas = row.getValue('MEAS')&amp;nbsp; #get the value for the next iteration &lt;/PRE&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;NOTE: I fairly unfamiliar with python so you may have to tweak the syntax to make this work&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:36:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329391#M25612</guid>
      <dc:creator>TerrySilveus</dc:creator>
      <dc:date>2021-12-11T15:36:12Z</dc:date>
    </item>
    <item>
      <title>Re: Need Python Example: sort rows, subtract current from next, load in new field</title>
      <link>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329392#M25613</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
rows = UpdateCursor(...)

count = 0

for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if count != 0: # if this isn't the first time in the loop (ie. if you have a number to subtract)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count = count + 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.blankcolumnname = row.MEAS - previous # make the blank column = current - previous
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row) # updates the whole row, now with a value for the blank column
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; previous = row.MEAS # sticks the current value into the previous variable for the next time through the loop

del row
del rows # remove row locks
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:36:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329392#M25613</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-11T15:36:14Z</dc:date>
    </item>
    <item>
      <title>Re: Need Python Example: sort rows, subtract current from next, load in new field</title>
      <link>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329393#M25614</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks so much!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;But I ru the code I get an error: 'module' object has no attribute 'Update'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;What would that be?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Apr 2011 15:49:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329393#M25614</guid>
      <dc:creator>NatalieLepsky</dc:creator>
      <dc:date>2011-04-21T15:49:40Z</dc:date>
    </item>
    <item>
      <title>Re: Need Python Example: sort rows, subtract current from next, load in new field</title>
      <link>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329394#M25615</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;start with:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;import arcpy&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;and the actual update cursor statement should be like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;rows = arcpy.UpdateCursor(FILL IN YOUR PARAMETERS HERE)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Apr 2011 15:54:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329394#M25615</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2011-04-21T15:54:34Z</dc:date>
    </item>
    <item>
      <title>Re: Need Python Example: sort rows, subtract current from next, load in new field</title>
      <link>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329395#M25616</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Fixed a typo and got no more errors. Thanks! But the field in my table didn't get updated...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I ran exactly what you sent me. What else could it be?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Import the arcpy &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Input feature class.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;rows = arcpy.UpdateCursor("C:/model_build/ModelBuildGeodatabase.mdb/locate_feature_layer_sort")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;count = 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for row in rows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if count != 0: &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count = count + 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.MEAS_DIST = row.MEAS - previous &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row) &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; previous = row.MEAS &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;del row&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;del rows&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Apr 2011 16:54:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329395#M25616</guid>
      <dc:creator>NatalieLepsky</dc:creator>
      <dc:date>2011-04-21T16:54:01Z</dc:date>
    </item>
    <item>
      <title>Re: Need Python Example: sort rows, subtract current from next, load in new field</title>
      <link>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329396#M25617</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It probably won't update if the table is open...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I tested this code below and it works.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy

myFile = "c:/gis/temp.shp"
sortField = "MEAS"
newField = "NEW"

rows = arcpy.UpdateCursor(myFile,"","","",sortField + " A") # sort by sort field
firstTime = True
for row in rows:
&amp;nbsp;&amp;nbsp; if firstTime:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; previous = row.getValue(sortField) #in your first iteration you will not have anything to update you just need to get the value for the next iteration
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; firstTime = False
&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue(newField, row.getValue(sortField) - previous)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; previous = row.getValue(sortField)&amp;nbsp; #get the value for the next iterationexcept:

del row
del rows
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:36:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329396#M25617</guid>
      <dc:creator>TerrySilveus</dc:creator>
      <dc:date>2021-12-11T15:36:17Z</dc:date>
    </item>
    <item>
      <title>Re: Need Python Example: sort rows, subtract current from next, load in new field</title>
      <link>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329397#M25618</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Oops - in my example I never gave it any commands for what to do if it was the first time around the loop, so the counter stayed at 0 and never got into the update part. Here's what it should be (you could also add an updateRow to the else part if you want the very first row to have a value - this way it will just be skipped over).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if count != 0: # if this isn't the first time in the loop (ie. if you have a number to subtract)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count = count + 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.blankcolumnname = row.MEAS - previous # make the blank column = current - previous
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row) # updates the whole row, now with a value for the blank column
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; previous = row.MEAS # sticks the current value into the previous variable for the next time through the loop
&amp;nbsp;&amp;nbsp;&amp;nbsp; else: # do this if it is the first time in the loop
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count = 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; previous = row.MEAS
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:36:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329397#M25618</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-11T15:36:20Z</dc:date>
    </item>
    <item>
      <title>Re: Need Python Example: sort rows, subtract current from next, load in new field</title>
      <link>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329398#M25619</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Everything worked! Thank you all so much!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Apr 2011 18:06:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329398#M25619</guid>
      <dc:creator>NatalieLepsky</dc:creator>
      <dc:date>2011-04-21T18:06:05Z</dc:date>
    </item>
    <item>
      <title>Re: Need Python Example: sort rows, subtract current from next, load in new field</title>
      <link>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329399#M25620</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;There is something else that I need help with....&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I used the example (thread #9), and it worked for the fields where sortField and newField were both 'double' type. When I tried to do the calculations on the Date field mm/dd/yyyy hh:mm:ss AM/PM I get an error message. It says 'ValueError: Row: Invalid input value for SetValue'. My resulting field is 'double'. Do the fields have to be the same data type? Is it possible to use Date type is the calculations?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 Apr 2011 19:03:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329399#M25620</guid>
      <dc:creator>NatalieLepsky</dc:creator>
      <dc:date>2011-04-25T19:03:42Z</dc:date>
    </item>
    <item>
      <title>Re: Need Python Example: sort rows, subtract current from next, load in new field</title>
      <link>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329400#M25621</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try something like this&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import datetime, time #not sure if you need both of these


myFile = "c:/gis/temp.shp"
sortField = "theDate"
newField = "NEW"

rows = arcpy.UpdateCursor(myFile,"","","",sortField + " A") # sort by sort field
firstTime = True
for row in rows:
&amp;nbsp;&amp;nbsp; if firstTime:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; previous = row.getValue(sortField) #in your first iteration you will not have anything to update you just need to get the value for the next iteration
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; firstTime = False
&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #row.setValue(newField, row.getValue(sortField) - previous)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; current = row.getValue(sortField)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; difference = current-previous # datetime.timedelta object (time difference)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue(newField, difference.days) # number of days
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; previous = current&amp;nbsp; #get the value for the next iteration&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:36:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329400#M25621</guid>
      <dc:creator>TerrySilveus</dc:creator>
      <dc:date>2021-12-11T15:36:22Z</dc:date>
    </item>
    <item>
      <title>Re: Need Python Example: sort rows, subtract current from next, load in new field</title>
      <link>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329401#M25622</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That code worked, thanks! But when I define the 'NEW' field as date - I get 12:00 AM for all rows. When I define 'NEW' as double - it comes out as 0. Which is correct - 0 days. I tried to multiply by 24 to get hours - still zeros. Is there any way to solve that?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Apr 2011 13:49:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329401#M25622</guid>
      <dc:creator>NatalieLepsky</dc:creator>
      <dc:date>2011-04-26T13:49:33Z</dc:date>
    </item>
    <item>
      <title>Re: Need Python Example: sort rows, subtract current from next, load in new field</title>
      <link>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329402#M25623</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I was wrestling with time fields yesterday (they were all getting reset to 12:00am). Apparently, &lt;/SPAN&gt;&lt;A href="http://forums.esri.com/Thread.asp?c=93&amp;amp;f=1149&amp;amp;t=232166"&gt;shapefiles do not understand time&lt;/A&gt;&lt;SPAN&gt;, so they become 12:00am (or zero). The time data is gone, it's not being hidden by the datatype, so multiplying by 24 will not help. I ended up working in a Personal Geodatabase - they understand time.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Apr 2011 15:06:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329402#M25623</guid>
      <dc:creator>DarrenWiens1</dc:creator>
      <dc:date>2011-04-26T15:06:22Z</dc:date>
    </item>
    <item>
      <title>Re: Need Python Example: sort rows, subtract current from next, load in new field</title>
      <link>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329403#M25624</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;That code worked, thanks! But when I define the 'NEW' field as date - I get 12:00 AM for all rows. When I define 'NEW' as double - it comes out as 0. Which is correct - 0 days. I tried to multiply by 24 to get hours - still zeros. Is there any way to solve that?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You'll need to have a field that recognizes time to get that information.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Apr 2011 15:40:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329403#M25624</guid>
      <dc:creator>TerrySilveus</dc:creator>
      <dc:date>2011-04-26T15:40:23Z</dc:date>
    </item>
    <item>
      <title>Re: Need Python Example: sort rows, subtract current from next, load in new field</title>
      <link>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329404#M25625</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Please help! I am new to Python. &lt;BR /&gt;&lt;BR /&gt;I created a model in ModelBuilder. The last steps are to grab the attribute table of the feature class, sort MEAS column in ascending order and then subtract next value from current and load those values in the new field. (I have an empty field in the attribute table). &lt;BR /&gt;&lt;BR /&gt;I wrote a simple script, but all I could do is to sort the MEAS column and print values out. &lt;BR /&gt;Could anybody be so kind and get me an example code?....&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; ---&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Natalie- I've done something similar in the 9.3 scripting environment using some of Richard Crissup's code (he had an ArcScript posting on June 27, 2008 called date_diff.py).&amp;nbsp; Basically, you start with a GPS generated track point shapefile with a time stamp field.&amp;nbsp; To that, the python script adds a numeric double field, and in the new field, calculates the difference in hours between the timestamp field in each record and the next, so one can sum up the amount of time spent in an area.&amp;nbsp; You have to know how the date field comes to you.&amp;nbsp; The script takes a while to execute, but gets the job done.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm new to Python, too, so please people, go easy on me, too:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcgisscripting, sys, os, re
import time, calendar, string, decimal

def func_check_format(time_string):
 if time_string.find("/") == -1:
&amp;nbsp; print "Error: time string doesn't contain any '/' expected format \
&amp;nbsp; is month/day/year hour:minutes:seconds"
 elif time_string.find(":") == -1:
&amp;nbsp; print "Error: time string doesn't contain any ':' expected format \
&amp;nbsp; is month/day/year hour:minutes:seconds"
 
 list = time_string.split()
 if (len(list)) &amp;lt;&amp;gt; 2:
&amp;nbsp; print "Error time string doesn't contain and date and time separated \
&amp;nbsp; by a space. Expected format is 'month/day/year hour:minutes:seconds'"


def func_parse_time(time_string):
&amp;nbsp;&amp;nbsp;&amp;nbsp; '''
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; take the time value and make it into a tuple with 9 values
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; example = "2004/03/01 23:50:00". If the date values don't look like this
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; then the script will fail. 
&amp;nbsp;&amp;nbsp;&amp;nbsp; '''
&amp;nbsp;&amp;nbsp;&amp;nbsp; year=0;month=0;day=0;hour=0;minute=0;sec=0;
&amp;nbsp;&amp;nbsp;&amp;nbsp; time_string = str(time_string)
&amp;nbsp;&amp;nbsp;&amp;nbsp; l=time_string.split()
&amp;nbsp;&amp;nbsp;&amp;nbsp; if not len(l) == 2:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddError("Error: func_parse_time, expected 2 items in list l got" + str(len(l)) + "time field value = " + time_string)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; raise Exception 
&amp;nbsp;&amp;nbsp;&amp;nbsp; cal=l[0];cal=cal.split("/")
&amp;nbsp;&amp;nbsp;&amp;nbsp; if not len(cal) == 3:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddError("Error: func_parse_time, expected 3 items in list cal got " + str(len(cal)) + "time field value = " + time_string)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; raise Exception
&amp;nbsp;&amp;nbsp;&amp;nbsp; ti=l[1];ti=ti.split(":")
&amp;nbsp;&amp;nbsp;&amp;nbsp; if not len(ti) == 3:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddError("Error: func_parse_time, expected 3 items in list ti got " + str(len(ti)) + "time field value = " + time_string)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; raise Exception
&amp;nbsp;&amp;nbsp;&amp;nbsp; if int(len(cal[0]))== 4:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; year=int(cal[0])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; month=int(cal[1])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; day=int(cal[2])
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; year=int(cal[2])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; month=int(cal[0])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; day=int(cal[1])&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; hour=int(ti[0])
&amp;nbsp;&amp;nbsp;&amp;nbsp; minute=int(ti[1])
&amp;nbsp;&amp;nbsp;&amp;nbsp; sec=int(ti[2])
&amp;nbsp;&amp;nbsp;&amp;nbsp; #formated tuple to match input for time functions
&amp;nbsp;&amp;nbsp;&amp;nbsp; result=(year,month,day,hour,minute,sec,0,0,0)
&amp;nbsp;&amp;nbsp;&amp;nbsp; return result
 
 
#----------------------------------------------------------------------------

def func_time_diff(start_t,end_t):
&amp;nbsp;&amp;nbsp;&amp;nbsp; '''
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Take the two numbers that represent seconds
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; since Jan 1 1970 and return the difference of
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; those two numbers in hours. There are 3600 seconds
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; in an hour. 60 secs * 60 min&amp;nbsp;&amp;nbsp; '''
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; start_secs = calendar.timegm(start_t)
&amp;nbsp;&amp;nbsp;&amp;nbsp; end_secs = calendar.timegm(end_t)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; x=abs(end_secs - start_secs)
&amp;nbsp;&amp;nbsp;&amp;nbsp; #diff = number hours difference
&amp;nbsp;&amp;nbsp;&amp;nbsp; #as ((x/60)/60)
&amp;nbsp;&amp;nbsp;&amp;nbsp; diff = float(x)/float(3600)&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; return diff

#----------------------------------------------------------------------------

print "Executing getnextLTIME.py script..."

try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp = arcgisscripting.create(9.3)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # set parameter to what user drags in
&amp;nbsp;&amp;nbsp;&amp;nbsp; fcdrag = gp.GetParameterAsText(0)
&amp;nbsp;&amp;nbsp;&amp;nbsp; psplit = os.path.split(fcdrag)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; folder = str(psplit[0]) #containing folder
&amp;nbsp;&amp;nbsp;&amp;nbsp; fc = str(psplit[1]) #feature class
&amp;nbsp;&amp;nbsp;&amp;nbsp; fullpath = str(fcdrag)

&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Workspace = folder

&amp;nbsp;&amp;nbsp;&amp;nbsp; fldA = gp.GetParameterAsText(1) # Timestamp field
&amp;nbsp;&amp;nbsp;&amp;nbsp; fldDiff = gp.GetParameterAsText(2) # Hours field
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # set the toolbox for adding the field to data managment
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Toolbox = "management"
&amp;nbsp;&amp;nbsp;&amp;nbsp; # add the user named hours field to the feature class
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.addfield (fc,fldDiff,"double")
&amp;nbsp;&amp;nbsp;&amp;nbsp; #gp.addindex(fc,fldA,"indA","NON_UNIQUE", "ASCENDING")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; desc = gp.describe(fullpath)
&amp;nbsp;&amp;nbsp;&amp;nbsp; updateCursor = gp.UpdateCursor(fullpath, "", desc.SpatialReference, fldA+"; "+fldDiff, fldA)
&amp;nbsp;&amp;nbsp;&amp;nbsp; row = updateCursor.Next()
&amp;nbsp;&amp;nbsp;&amp;nbsp; count = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp; oldtime = str(row.GetValue(fldA))
&amp;nbsp;&amp;nbsp;&amp;nbsp; #check datetime to see if parseable
&amp;nbsp;&amp;nbsp;&amp;nbsp; func_check_format(oldtime)
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.addmessage("Calculating " + fldDiff + " field...")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; while row &amp;lt;&amp;gt; None:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if count == 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.SetValue(fldDiff, 0)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; start_t = func_parse_time(oldtime)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b = str(row.GetValue(fldA))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end_t = func_parse_time(b)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; diff_hrs = func_time_diff(start_t, end_t)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.SetValue(fldDiff, diff_hrs)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; oldtime = b
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; count += 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; updateCursor.UpdateRow(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row = updateCursor.Next()

&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.addmessage("Updated " +str(count+1)+ " rows.")
&amp;nbsp;&amp;nbsp;&amp;nbsp; #gp.removeindex(fc,"indA")
&amp;nbsp;&amp;nbsp;&amp;nbsp; del updateCursor
&amp;nbsp;&amp;nbsp;&amp;nbsp; del row
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
except Exception, ErrDesc:
&amp;nbsp;&amp;nbsp;&amp;nbsp; import traceback;traceback.print_exc()
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
print "Script complete."
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:36:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329404#M25625</guid>
      <dc:creator>RussellKallstrom</dc:creator>
      <dc:date>2021-12-11T15:36:25Z</dc:date>
    </item>
    <item>
      <title>Re: Need Python Example: sort rows, subtract current from next, load in new field</title>
      <link>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329405#M25626</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;---&lt;BR /&gt;You have to know how the date field comes to you.&amp;nbsp; &lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Sorry, what I wrote is confusing, it is not actually a date type field; I'd like to clarify the timestamp field is actually a text/string type field.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've found that date fields generally tend to be difficult to deal with in ArcGIS, often resulting in more trouble than they're worth.&amp;nbsp; As a result, it's often more convenient to save them as text string fields.&amp;nbsp; Our data is coming off a tracklog saved from DNR Garmin, where the LTIME field was created and stored as a text field, length 20 characters.&amp;nbsp; You might want to use the text field approach unless you have other reasons for sticking to the date data type.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 May 2011 01:07:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329405#M25626</guid>
      <dc:creator>RussellKallstrom</dc:creator>
      <dc:date>2011-05-04T01:07:24Z</dc:date>
    </item>
    <item>
      <title>Re: Need Python Example: sort rows, subtract current from next, load in new field</title>
      <link>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329406#M25627</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi, I found this thread because I am looking to do the same thing as the OP.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried the codes from both #9 and #10 and both times I got the same error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Runtime error &amp;lt;type 'exceptions.TypeError'&amp;gt;: unsupported operand type(s) for -: 'int' and 'NoneType'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have limited Python experience so I don't know for sure what that error means, I've interpreted it as that it does not recognize the variable 'previous' as something that can be subtracted. Do I need to somehow define 'previous' before the conditional?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Jun 2012 15:51:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-python-example-sort-rows-subtract-current/m-p/329406#M25627</guid>
      <dc:creator>AliceThomas-Smyth</dc:creator>
      <dc:date>2012-06-14T15:51:35Z</dc:date>
    </item>
  </channel>
</rss>

