AnsweredAssumed Answered

Arcpy - Updating attribute in the last row of a table with an Update Cursor

Question asked by trillevine on Feb 29, 2016
Latest reply on Feb 29, 2016 by trillevine

Hello All,


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.  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.  Does anyone have any ideas?  Any feedback is greatly appreciated!


My code so far:


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):
    command = 'echo ' + text.strip() + '| clip'
# call function to copy UID from arcpar.txt to clipboard

with arcpy.da.UpdateCursor(punkte, returnField, where_clause=None, sql_clause=sql_clause) as cursor:
    last_row =
    lastUID = last_row[1]