<?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 - Updating attribute in the last row of a table with an Update Cursor in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-updating-attribute-in-the-last-row-of-a/m-p/396378#M31290</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have you tried updating the row with 'cursor.updateRow(row)'?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/188110_pastedImage_0.png" style="max-width: 1200px; max-height: 900px;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 29 Feb 2016 14:19:25 GMT</pubDate>
    <dc:creator>MitchHolley1</dc:creator>
    <dc:date>2016-02-29T14:19:25Z</dc:date>
    <item>
      <title>Arcpy - Updating attribute in the last row of a table with an Update Cursor</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-updating-attribute-in-the-last-row-of-a/m-p/396377#M31289</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying to update the value in a specific field ('uid_n') in the last row of a table with a value read out of a text file.&amp;nbsp; I've figured out how to return the last value in the table for the uid_n field, but am struggling with the actual update bit.&amp;nbsp; Does anyone have any ideas?&amp;nbsp; Any feedback is greatly appreciated!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My code so far:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
from arcpy import env
import os

# open arcpar.txt
arcpar = open(r'C:\Users\admin\Desktop\ToeB 10.2\arcpar.txt')
# read UID line
line = arcpar.readlines()[1]
UID = line[4:-1]
# set workspace for arcpy
env.workspace = r'C:\Users\admin\Desktop\ToeB 10.2\Data Svenja\Toeb Svenja.gdb'
# possible feature classes
punkte = 'Punktobjekt'
# field to use to find last record in table
objectId = 'OBJECTID_1'
returnField = ["OBJECTID_1", "uid_n"]
sql_clause = (None,'ORDER BY {} DESC'.format(objectId))
last_row = ''
last_OID = ''

# function to copy text to clipbard
def addToClipBoard(text):
&amp;nbsp;&amp;nbsp;&amp;nbsp; command = 'echo ' + text.strip() + '| clip'
&amp;nbsp;&amp;nbsp;&amp;nbsp; os.system(command)
# call function to copy UID from arcpar.txt to clipboard
addToClipBoard(UID)

with arcpy.da.UpdateCursor(punkte, returnField, where_clause=None, sql_clause=sql_clause) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; last_row = cursor.next()
&amp;nbsp;&amp;nbsp;&amp;nbsp; lastUID = last_row[1]&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 18:07:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-updating-attribute-in-the-last-row-of-a/m-p/396377#M31289</guid>
      <dc:creator>TrilliumLevine1</dc:creator>
      <dc:date>2021-12-11T18:07:59Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy - Updating attribute in the last row of a table with an Update Cursor</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-updating-attribute-in-the-last-row-of-a/m-p/396378#M31290</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have you tried updating the row with 'cursor.updateRow(row)'?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/188110_pastedImage_0.png" style="max-width: 1200px; max-height: 900px;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Feb 2016 14:19:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-updating-attribute-in-the-last-row-of-a/m-p/396378#M31290</guid>
      <dc:creator>MitchHolley1</dc:creator>
      <dc:date>2016-02-29T14:19:25Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy - Updating attribute in the last row of a table with an Update Cursor</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-updating-attribute-in-the-last-row-of-a/m-p/396379#M31291</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mitch, thanks for the quick feedback.&amp;nbsp; When I run that I get an error: 'row' is not defined.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Feb 2016 14:23:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-updating-attribute-in-the-last-row-of-a/m-p/396379#M31291</guid>
      <dc:creator>TrilliumLevine1</dc:creator>
      <dc:date>2016-02-29T14:23:18Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy - Updating attribute in the last row of a table with an Update Cursor</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-updating-attribute-in-the-last-row-of-a/m-p/396380#M31292</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The error says 'row' is not defined because in Mitch's code there is no variable 'row', hence it is undefined when you try to update the cursor based on a non-existent variable.&amp;nbsp; I am not sure I completely understand what value you are trying to use to update the row with, but does the following work:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;with arcpy.da.UpdateCursor(punkte, returnField, where_clause=&lt;SPAN class="special"&gt;None, sql_clause=sql_clause) as cursor:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; last_row = cursor.next()
&amp;nbsp;&amp;nbsp;&amp;nbsp; last_row[&lt;SPAN class="number"&gt;1] = UID&lt;/SPAN&gt;
&lt;SPAN class="number"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow(last_row)&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN class="number"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 18:08:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-updating-attribute-in-the-last-row-of-a/m-p/396380#M31292</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-11T18:08:02Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy - Updating attribute in the last row of a table with an Update Cursor</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-updating-attribute-in-the-last-row-of-a/m-p/396381#M31293</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Joshua, yeah, that's exactly what I was looking for, I was missing the [1] in there.&amp;nbsp; Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Feb 2016 14:54:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-updating-attribute-in-the-last-row-of-a/m-p/396381#M31293</guid>
      <dc:creator>TrilliumLevine1</dc:creator>
      <dc:date>2016-02-29T14:54:12Z</dc:date>
    </item>
  </channel>
</rss>

