As the title says, I am using arcpy.da.UpdateCursor() and I can't get it to update the rows. My code is below. (Yes, I know I am still working with a nested cursor... I haven't decided if a dictionary is the right way to go for my purposes yet. That's for another topic.)
fields = ["SOIL", "MAX_SLOPE", "MIN_CDA", "MAX_CDA", "WT_SEP", "WT_RELAX", "COAST_SEP", "MIN_DEPTH", "DEPTH_RELA", "COAST_MIN_", "BMP", "MOD"] for row in arcpy.da.SearchCursor(combo_table, ["DARAS", "HSG", "MEDSLOPE", "MEDWT"]): print("Saving constraint table for DA " + str(row[0]) + " and HSG " + str(row[1]) + "...") arcpy.Copy_management(compare, BMPFold + "\\" + "DA" + str(row[0]) + "HSG" + str(row[1])) arcpy.AddField_management(BMPFold + "\\" + "DA" + str(row[0]) + "HSG" + str(row[1]), "MOD", "TEXT", "", "", 25) with arcpy.da.UpdateCursor(BMPFold + "\\" + "DA" + str(row[0]) + "HSG" + str(row[1]), fields) as cursor: for r in cursor: # Compare water table depths if r[4] + r[7] > row[3]: if r[5] == 1: coast_WT = r[6] else: coast_WT = r[4] if r[8] == 1: coast_depth = r[9] else: coast_depth = r[7] if coast_WT + coast_depth < row[3]: if r[5] == 1 and r[8] == 1: r[11] = "Separation and Depth" print("Modifying " + str(r[11]) + "allows for " + str(r[10]) + "...") elif r[5] == 1: r[11] = "WT Separation" print("Modifying " + str(r[11]) + "allows for " + str(r[10]) + "...") elif r[8] == 1: r[11] = "Practice Depth" print("Modifying " + str(r[11]) + "allows for " + str(r[10]) + "...") cursor.updateRow(r) if coast_WT + coast_depth > row[3]: print("Removing " + str(r[10]) + " from DA " + str(row[0]) + " HSG " + str(row[1]) +" based on water table proximity...") cursor.deleteRow()
As the title states, I am not getting any errors when I run this code. When I open my file, the "MOD" field is blank for all rows still. My print statements are not printing before or after the r[11] = "TEXT" line even when they are modified to exclude calling r[11]. They worked at one point while I was getting errors with cursor.updateRow() but now there's nothing. My last print statement works, "Removing ..." though.
Solved! Go to Solution.
Oh no... I wish I could delete stuff from here so I can hide my shame.
I changed the operator at one point and it wasn't updating anything because there wasn't anything to update. :X The main IF statement was always false. Sorry for wasting your time, everyone.
cursor.update row...line 29 needs to have its spacing adjusted it is improperly indented (either in or out...can't tell)
I've tried moving it all around and I did it again to be sure. Still nothing. If it needs to be on the same level of indentation as the elif statement above it, it's in the right spot.
Oh no... I wish I could delete stuff from here so I can hide my shame.
I changed the operator at one point and it wasn't updating anything because there wasn't anything to update. :X The main IF statement was always false. Sorry for wasting your time, everyone.
Rachael, just FYI, if you created the question/discussion, you should be able to erase it all...if you really want. it should ease from that point down...so erase the original question if you really "want to hide your shame"