1

I've written a python script (ArcGIS 10.0) for importing point objects from Excel sheets to our ArcSDE database. This works fine, but I'd like to make this script a bit more custamizable by the user and therefore want to use a python list for updating my data. I've tried the following, but unfortunately the update cursor does not work together with a python list and I'm getting the error "Field item does not exist".

import os, arcpy

fc = r"C:\temp\temp.gdb\tempFC"
rowlist = [("NAME", "Testname"),("COMMENT", "Testcomment")]

print "Normal UpdateCursor"
fcCursor = arcpy.UpdateCursor(fc)
for row in fcCursor:
    row.NAME = "test 1"
    row.COMMENT = "test 1"
    fcCursor.updateRow(row)
del row
del fcCursor
print "Finished"

print "UpdateCursor with python list"
fcCursor = arcpy.UpdateCursor(fc)
for row in fcCursor:
    for item in rowlist:
        row.item[0] = item[1]
    fcCursor.updateRow(row)
del row
del fcCursor
print "Finished"

I've also tried

variable = "row.%s = %s" % (item[0], item[1])
variable

instead of

row.item[0] = item[1]

I'm not getting an error anymore, but nothing will be updated then.

Anyone another idea how to make this work?

  • 1
    May want to show where the error occurs. – recurvata Oct 5 '15 at 11:36
3

You are trying to access the fields dynamically, which overall is a good strategy, but it does require a different syntax.

You are getting an error around row.item[0] because you are telling arcpy to update the field called item which doesn't exist, instead of the field that is named the value of item[0].

Instead you should be using setValue:

for row in fcCursor:
    for item in rowlist:
        row.setValue(item[0], item[1])
    fcCursor.updateRow(row)
  • Great, that's what I was looking for! I already realized that arcpy treats my variable as field name but did not know the syntax to solve this problem. I've had a quick search for setValue and found out, that ESRI added this example to it's 10.1 Help page of the UpdateCursor, but it's missing on the 10.0 pages... Thank you Evil Genius! – ateko Oct 5 '15 at 13:32

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.