1

My dates (maxDate, minDate, avgDate) all print out with the correct datetime format, but I am unsure if the problem is how the loop is written to update the cursor.

Error:

line 102, in updateRow return convertArcObjectToPythonObject(self._arc_object.UpdateRow(*gp_fixargs(args))) RuntimeError: ERROR 999999: Error executing function.

Code:

arcpy.env.workspace =  r"C:\ForChris\wetMatchs\SBA_wetlandTR_int\SBA.gdb"
fcs = arcpy.ListFeatureClasses()
years = []
yearsJD = []
for fc in fcs:
    arcpy.AddField_management(fc, "Max_Year", "Date")
    arcpy.AddField_management(fc, "Min_Year", "Date")
    arcpy.AddField_management(fc, "Avg_Year", "Date")

    cursor = arcpy.SearchCursor(fc)
    for row in cursor:
        fDate = row.getValue("Final_Date")
        a = (14 - fDate.month)//12 ## Julian date calc
        y = fDate.year + 4800 - a
        m = fDate.month + 12*a - 3
        JD = fDate.day + ((153*m + 2)//5) + 365*y + y//4 - y//100 + y//400 - 32045
        yearsJD.append(JD)
        years.append(fDate) 
    averageJD = sum(yearsJD) / len(yearsJD) ## calculates average julian date
    az = averageJD + 32044 ## convert julian date to calendar date
    b = (4*az + 3)//146097
    c = az - (146097*b)//4
    d = (4*c + 3)//1461
    e = c - (1461*d)//4
    n = (5*e + 2)//153    
    aday = e + 1 - (153*n + 2)//5
    amonth = n + 3 - 12*(n//10)
    ayear = 100*b + d - 4800 + n/10
    avgDate = datetime.datetime(ayear, amonth, aday)
    minDate = numpy.min(years)
    maxDate = numpy.max(years)

    cursor2 = arcpy.UpdateCursor(fc)
    for row2 in cursor2:
        row2.setValue("Max_Year", maxDate)
        row2.setValue("Min_Year", minDate)
        row2.setValue("Avg_Year", avgDate)
        cursor.updateRow(row2)
    del years[0:len(years)] ### Empties List
    del yearsJD[0:len(yearsJD)]

closed as off-topic by Vince, PolyGeo Jul 2 '15 at 22:00

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Vince, PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

2

Your problem is at line 102 with cursor.updateRow(row2), where it appears you forgot you were using cursor2 (not cursor, as cursor is your searchcursor and cursor2 is your updatecursor).

  • Oh silly me, thank you very much! I am a newcomer to python. – Chris Jul 2 '15 at 21:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.