0

I wanted to copy a specific row of a table to another new table. So what I did was,

  1. copy the data of the row to a particular Array called c[].
  2. Write them to a file Geodatabase table called Dead_T

I have completed the 1st step. Now I want to do the 2nd step. I have tried the following code for step 2, but it is not working. Can anyone tell me the mistake that I have made here? (Here filedname is one of the names of columns available in the table Dead_T)

Dead_T='C:\Users\Shanaka\Desktop\TL _HAndling\cad\Cad_Data.gdb\DD_IF'
with arcpy.da.UpdateCursor(Dead_T, "filedname") as cursor1:
    for row1 in cursor1:
        row1[0] = c[0]
        arcpy.AddMessage ("done")

        cursor1.updateRow(row1)
  • 3
    UPDATE changes an existing row. INSERT creates a new one. Your c variable is not defined. Do you really want to clobber every row with the first element of the array? – Vince Nov 22 '18 at 15:04
1

As mentioned in the comment, you must use an insert cursor here because update cursor work for changing the values of existing rows:

# I assume that DT and c are defined, the fieldnames exist in DT and c is a list of list with two item.
with arcpy.da.InsertCursor(DT, ("fieldname1","fieldname2")) as cursor:
    for row in c: #take each row of c
        cursor.insertRow(c) 
  • Thanks a lot. This really helps me. It is working now – Shanaka Herath Nov 25 '18 at 6:52

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.