1

I have list with values and I want to put them in rows for specific column. Here is my code:

den = kol() # list with values
with arcpy.da.UpdateCursor('Wojewodztwa', 'gest_zal') as cursor:
    for row in cursor:
        for i in range(len(den)):
            row.setValue(den[i])

During execution I've got error: 'list' object has no attribute 'setValue'. I also try to iterate throught list and set row[0] = den[i] but all I got was that all values in rows are the same last number. How can I make it work?

2

You should access the fields using index position according to your cursor. In your case field "gest_zal" would be row[0]

Then you must store your update: cursor.Update(row)

Then its not clear to me if you want to update a table without actually knowing which value goes where, or add the list to a table. Your loop set the row value several times, always ending at the last on each row.

If you want to add the list to table "Wojewodzta" the code would look something like

den = kol() # list with values

arcpy.da.InsertCursor('Wojewodztwa', ['gest_zal']) as cursor:
for currDen in den:
       cursor.insertRow([currDen])

If you are trying to update the table your code does not really keep track of which row to update, but something like this would update the column gest_zal with one of the values from den. However its probably pretty useless as you don't know for sure in which order the cursor loops the table and if you don't have as many items in den as in the table it will fail. Maybe you need another attribute to match the row against the list?

den = kol() # list with values
i=0
with arcpy.da.UpdateCursor('Wojewodztwa', ['gest_zal']) as cursor:
    for row in cursor:
        row[0]=den[i]
        cursor.UpdateRow(row)
        i=i+1

Read more here: http://resources.arcgis.com/en/help/main/10.2/index.html#//002z0000001q000000

  • Thank you very much! It worked. In this particular case I've sorted my values before setting them to rows. – Krzysztof Żuraw Nov 20 '14 at 20:54
0

You are using the setValue method which is related to the old cursor, for the da cursor use:

row[indexNumberToUpdate] = newValue # either a variable or a reference to another field/value
        cursor.updateRow(row)

e.g

row[0] = newValue # either a variable or a reference to another field/value
        cursor.updateRow(row)

See link below for further examples.

UpdateCursor (arcpy.da)

  • Is there any way other than row[indexNumber]? I have too many fields with complicated names so I dont want to write all that in the cursor statement and count what is the index of which field. – Salman Jun 30 '16 at 14:19

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.