str object has no attribute append

1482
1
01-09-2013 09:31 AM
EmilyAgar1
New Contributor
I am trying to run an array where it loops through my "Cont_Buff" layer selects the first record, then selects all the culverts from the "Culvert_subset" layer that fall within that first record. Then takes the GWP value from the "Cont_Buff" layer and applies it to the WP field for all the selected culverts in the "Culvert_subset" layer. Once it has done this for the first record loop back and do the same for the second record in the "Cont_Buff" layer and so on.

However I have not been able to make it run past the loop because I am getting an 'str object has no attibute error'. My OBJECTID type is not string it is Long.
I've included the entire code block.
rows = arcpy.SearchCursor("Cont_Buff")
row = rows.next()

CUL_rows = arcpy.UpdateCursor("Culvert_subset")
CUL_row = rows.next()

while row:
    a = row.OBJECTID
    "OBJECTIDS".append(a)
    row = rows.next()

    #Set Count equal to the length of the array created in the while loop
    Count = len("OBJECTID")

#iterate through each individual feature by using a definition query
while Position < Count: 
    query = "[OBJECTID] = " + "'" + OBJECTIDs[Position] + "'"
    "Cont_BUff".definitionQuery = query

    #center on feature
    df.panToExtent("Cont_Buff".getSelectedExtent())

    #Select all of the Culverts Cells within the active Site Boundary
    arcpy.SelectLayerByLocation_management("Culvert_subset","COMPLETELY_WITHIN","Cont_Buff",0,"NEW_SELECTION")

    #Set [WP] equal to Cont_Buff[GWP]
    hopper = '"' + str(OBJECTIDs[Position]) + '"'
    arcpy.CalculateField_management("Culvert_subset","WP",hopper,"VB","#")


I am not sure if this is even the correct way to do this seeing as how I cant get past the loop. Any suggestions?
Tags (2)
0 Kudos
1 Reply
T__WayneWhitley
Frequent Contributor
...I see that error when 'recycling' variables thinking I am appending to a list var, when in actuality I'm attempting appending to a string.  At any rate, the same methods aren't available...check your variables.

This makes no sense:
"OBJECTIDS".append(a)

At a glance, it looks like you want to append OBJECTIDs to create a list var called 'a' to contain all your OBJECTID values?

I am not convinced this is a good idea, but you could do something like this:
a = []
while row:
     a.append(row.OBJECTID)
     row = rows.next()

#Set Count equal to the length of the list variable created in the while loop
Count = len(a)


Also, check your indention - it isn't quite right either.  Also, if you need a count, there is a Get Count tool in Data Management....I think there is a property get from a Describe object too, but it'll suffice to say iterating the records with a cursor is not necessary.
0 Kudos