I wanted to copy a specific row of a table to another new table. So what I did was,
- copy the data of the row to a particular Array called
c[]
. - 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)
1 Answer 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 nowShanaka Herath– Shanaka Herath2018年11月25日 06:52:17 +00:00Commented Nov 25, 2018 at 6:52
c
variable is not defined. Do you really want to clobber every row with the first element of the array?