AnsweredAssumed Answered

Copy attribute values from one table to another, in a loop

Question asked by on Jun 5, 2014
Latest reply on Nov 23, 2016 by judsoncrouch
I am trying to copy the attribute values from one table to another, inside a loop.  I am looping through one table and inside that loop I want to copy the attribute values to another table.  I have copied attribute values over before, but using JoinField, but I do not want to use that in this code, as I am already looping through records.  I have seen different code attempting to do this, but so far nothing has worked for me.  The code I'm working with is:

import arcpy import os import string import subprocess  arcpy.env.workspace = r"c:\Users\matt\Desktop\Ditch\Database\Centerline.mdb" assetFeatureClass = "[Assets]" assetrows = arcpy.UpdateCursor(assetFeatureClass,"[Processed] <> 'Y'","","","")  # for each row in the result set for row in assetrows:         print row.getValue("Ditch_ID")          #create asset         #Insert code to call out ArcObjects utility...         centerline = "[Pipeline_Centerline]"                  #update asset record attributes from asset table         rows = arcpy.UpdateCursor(centerline)         for row in rows:                 row.Ditch_ID = assetFeatureClass.Ditch_ID                  rows.updateRow(row)

I get an error that states:

Runtime error  Traceback (most recent call last):   File "<string>", line 24, in <module> AttributeError: 'str' object has no attribute 'Ditch_ID'

and I assume what is causing this is the row.Ditch_ID = assetFeatureClass.Ditch_ID section.  What I am trying to do in this section is to copy to the current record in the Centerline table the 'Ditch_ID' attribute value from the outer loop's record in the Assets table.  Also, I have to do this for several attributes (both tables have the same schema) and need to either iterate over the code for each, or somehow copy several attributes at once.