0

My UpdateCursor isn't working in arcpy. Here's my code:

urows = arcpy.UpdateCursor(firstDatabase+ os.sep + "Temp")
for urow in urows:
    urow.Import_Date = time.strftime("%d/%m/%Y")
    urow.File_Name = str(table)
    urows.updateRow(urow)

It will always error out on the Import_Date field saying "error executing function".

The Import_Date is a 'date' field.

Any ideas?

Here is a screen shot of the loop when I add "arcpy.AddMessage(urow)" in the code and # out the other stuff.
enter image description here

12
  • What format is the Import_Date field?
    – nmpeterson
    Commented Aug 11, 2015 at 20:24
  • If you comment out the urow.Import_Date line, are you able to perform the urow.File_Name line without an error?
    – papadoo
    Commented Aug 11, 2015 at 20:32
  • It's a date field.
    – MjonesGEO
    Commented Aug 11, 2015 at 20:33
  • See here
    – Barbarossa
    Commented Aug 11, 2015 at 20:45
  • 1
    have you tried datetime.datetime.today()?
    – crmackey
    Commented Aug 11, 2015 at 21:30

2 Answers 2

1

Instead of using the dot field name notation that you are using, use the setValue/getValue notation instead. I just tried something like the following on a date field and it works fine:

urows = arcpy.UpdateCursor(os.path.join(firstDatabase, "Temp"))
for urow in urows:
    urow.setValue("Import_Date", time.strftime("%d/%m/%Y"))
    urow.setValue("File_Name", str(table))
    urows.updateRow(urow)
0

Try usin arcpy.da.UpdateCursor(fc, fields) . Then instead of using the dot field name notation, use the index e.g. row[0]. I recommend using a with statement and cursor.Make sure to commit by calling .updateRow more info here (http://resources.arcgis.com/de/help/main/10.2/index.html#//018w00000014000000)

Assuming you have 10.x, I am not sure if da.UpdateCursor existed in 9.x

1
  • 2
    The da cursors weren't available until 10.1
    – ianbroad
    Commented Aug 11, 2015 at 22:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.