I'm trying to update fields with updateCursor
, but it doesn't work at all.
I've worked with updateCursor
before many times but this time - no success.
I have a feature class (frameBoundaryBeforeAT
) in which I need to update his fields according to a text file. I extracted the name and other parameters from the text and append them into a list.
I'm going through the list and i compare between the name in the fc
and the name in the list= (if str(row[10]) == info_extract[0])
and if it's the same name, I want to update the other fields in fc
.
The loop is fine, it matches the names, the if is working (I've checked it with a simple print - print "it's a match") but when it's come to updating the field - nothing happened.
If I delete the if
and just update the fields with some random characters it works, but the if statement is ok so what is the problem?
I tried to print after the line: row[0] = info_extract[1]
, just to see what it does and I can see the name that I wanted, but when I open the fc
I see empty fields.
db = r"D:\Work work work\A\arc\per_day_GDB\Flight_020721.gdb"
txt = r"D:\Work work work\A\arc\Data_for_GDB\Best_fit_eop\noa.txt"
txt_list = extract_list_from_txt(txt)
frameBoundaryBeforeAT = db + "//frameBoundaryBeforeAT"
fieldnames = ["Frame","Camera","Easting","Northing","MSL_Height","Omega","Phi","Kappa","Date","Time","Feature_Name"]
for line in txt_list:
info_extract = extract_info_from_list(line)
with arcpy.da.UpdateCursor(frameBoundaryBeforeAT, fieldnames) as cursor:
for row in cursor:
if str(row[10]) == info_extract[0]:
print "it's a match"
row[0] = info_extract[1]
row[1] = "DMCIIe_250"
row[2] = info_extract[2]
row[3] = info_extract[3]
row[4] = info_extract[4]
row[5] = info_extract[5]
row[6] = info_extract[6]
row[7] = info_extract[7]
#Urow[8] = info_extract[8]
row[9] = info_extract[9]
cursor.updateRow(row)