Select to view content in your preferred language

Having problems with Runtime Error: Update Cursor

3098
10
12-01-2012 12:25 PM
VictoriaPutinski
Emerging Contributor
I am extremely new to Python, which will become evident in this post.
This script was working just fine before trying it on a new shapefile's attribute table.
No column or row names were changed.

Here is the code:
import arcpy
import sys, os, time, copy

def POIequals(r1,r2):
    pnts=0
    #samePOI
    if r1.poi_id==r2.poi_id:
        return True #If POI_ID is the same, it is assumed features are equal
    #sameAddress
    if r1.address==r2.address:
        pnts+=1
    #sameBank
    if r1.newname==r2.newname:
        pnts+=1
    #sameCity
    if r1.city==r2.city:
        pnts+=1
    #closeLoc
    if (r1.x<=r2.x+0.0005 and r1.x>=r2.x-0.0005) and (r1.y<=r2.y+0.0005 and r1.y>=r2.y-0.0005):
        pnts+=1
    if pnts >= 3: #three of the 5 tests above must pass for features to be considered equal
        return True
    else:
        return False
    

print "Starting process..."
start=time.strftime("%a, %d %b %Y %H:%M:%S")
print start+"\n"

inFC="C:\\Users\\Toir\\Documents\\My Dropbox\\EPOIDuplicatesRemoved\\ALLFIN2002_2011\\AllFin2002_2011_Montreal.dbf"

rowsWrite = arcpy.UpdateCursor(inFC)
total=int(arcpy.GetCount_management(inFC).getOutput(0))

c=0
chold=0

for rowW in rowsWrite:
    #set variables for loop:
    poi=rowW.poi_id
    year=rowW.epoi_year
    gain=True
    loss=True
    #find if point is a gain or loss (or both):
    #where="[poi_id] = '"+poi+"'"
    rowsRead = arcpy.SearchCursor(inFC) #add "___,where)" to improve speed
    for rowR in rowsRead:
        if POIequals(rowW,rowR):
            if year-1==rowR.epoi_year:
                gain=False
            if year+1==rowR.epoi_year:
                loss=False
            if not loss and not gain:
                break
    #set change variable:
    change=""
    if gain:
        change="Gain"
    if loss:
        change="Loss"
    if gain and loss:
        change="GainAndLoss"
    if not gain and not loss:
        change="None"
    rowW.change=change
    rowsWrite.updateRow(rowW)
    #end of loop tasks:
    del rowR, rowsRead
    if c==chold:
        print "  ->"+str(c)+" of "+str(total)+" features completed. ("+str(round((float(c)/float(total)*100.0),1))+"%)"
        chold+=100
    c+=1

#unlock and final message:
del rowW,rowsWrite
print "Complete!"
end=time.strftime("%a, %d %b %Y %H:%M:%S")
print "Started: "+start+"\nEnded:   "+end


Here is the error I get:

Traceback (most recent call last):
  File "C:\Users\Toir\Documents\My Dropbox\EPOIDuplicatesRemoved\ALLFIN2002_2011\findLossAndGainWorkingBroadEquals_edit.py", line 33, in <module>
    rowsWrite = arcpy.UpdateCursor(inFC)
  File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\__init__.py", line 825, in UpdateCursor
    return gp.updateCursor(*args)
  File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 362, in updateCursor
    self._gp.UpdateCursor(*gp_fixargs(args)))
RuntimeError: ERROR 999999: Error executing function.


Any help on this would be great, and ASAP please!
Tags (2)
0 Kudos
10 Replies
T__WayneWhitley
Honored Contributor
Ah, thanks Mathew, good to practice with!  Hope Victoria sees this one.
0 Kudos