ArcMap 10.6 Python,
I have a list of streetlight that I need ti update their location, these are stored in a text file, Pole#, X, Y. I iterate through the list and pass a SQ:L expression for the current pole number, and then hit an UpDateCursor. However I keep getting an error return without exception. I am using SDE with a version defined in the connection file. I've tested the SQL query and it returns records, and had a print for the row's with correct values, but the cursor.update(row) seems to fail. I have correct permissions to the SDE database for editing. Any Ideas,
import arcpy
fn = "LightCoords.txt"
'''
# Example of what's in the file.
P67298, 635610.433203, 970018.33444
P63082, 670047.572717, 1056312.84006
165131, 668496.444993, 1056333.22828
'''
# Open the file that has pole, X, Y and put into a list
slights = []
with open(fn) as file:
for item in file:
slights.append(item.split(','))
# SDE Connection
SDEConn ='ELECTEST.sde'
arcpy.env.workspace = SDEConn
lights = "Streetlight"
# Process: Start Edit
edit = arcpy.da.Editor(SDEConn )
edit.startEditing(False, True) # SystemError: error return without exception set #
edit.startOperation()
fields = ['PoleNUMBER', 'SHAPE@X', 'SHAPE@Y']
# Iterate through the list of lights
for i in slights:
a = (i[0].strip()) # Pole
b = i[1] # X
c = i[2] # Y
# create a valid where clause
sql = """{0} = '{1}' """.format(arcpy.AddFieldDelimiters(lights, 'PoleNUMBER'), a)
try:
# Update X, Y coordinates using an update cursor
with arcpy.da.UpdateCursor(lights, ['PoleNUMBER', 'SHAPE@X', 'SHAPE@Y'], where_clause=sql) as cursor:
for row in cursor:
# Update X, Y values here
row[1]= float(b)
row[2]= float(c)
cursor.updateRow(row)
except Exception as e:
print("An error occurred: {}".format(e))
edit.stopOperation()
# Commit edit to table
edit.stopEditing(True)
print("Done")