I want to figure out how to be able to update my field at the same time as I am adding my new rows into the table. This is just a dbf table not an attribute table. The attached are my codes, which work great for adding rows but I am getting error for updating the fields related to each new rows.

import arcpy

sc = arcpy.SearchCursor(r'C:\Users\contdata\Test3_1.gdb/New_Appended_Table')
cur = arcpy.da.InsertCursor(r'C:\Users\contdata\Test3_1.gdb/New_Appended_Table',('Test'))

index1 =[]

for row in sc:
    if len(lam)>0:
        index1= (lam.split(','))
        for i in index1:
            if n<=y:

for m in mylist:
    for row in tt:
    for x in mylist2:
        if m in x:

del cur

enter image description here

enter image description here

  • I don't follow what you're trying to do here. Your code appears to be reading values from a table, then creating new rows in the same table and populating a different field with values from your search cursor into those new records, and then you're looping through everything with your update cursor into the same table again populating yet another field with values. Can you please show a screenshot of your table and some detail of what you're doing with the different values? – Midavalo May 19 '17 at 23:11

You use your insert cursor as input for your update cursor. That doesn't make sense.

I am not quite sure what you are trying to achieve, but if you want to alter the data before you append them then just use the insert cursor and modify data before hand in the code.

cur = arcpy.da.InsertCursor(r'C:\Users\contdata\Test3_1.gdb/New_Appended_Table',('Test', 'Test1'))
for m in mylist:
    for x in mylist2:
        if m in x:

If you try to modify existing data without adding new data, just use the update cursor.

Either use the where clause as third argument (ie 'objectid= 123') to update a specific row or subset of rows or loop over all your rows as you did with your search cursor and update directly after you evaluated the values.

  • Yes, You were write. I did recognize it and edited my question but still getting error. – Koush May 19 '17 at 15:06
  • you need to define fields as tuples, similar to what you did with the insert cursor. But take at look at the code sample I added. To me it looks like you are trying to do something like this. – Thomas May 19 '17 at 15:29
  • Thx Thomas, you solution and suggestions was great and worked out correctly. Thx again for support and help – Koush May 21 '17 at 1:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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