I'm trying to delete a few rows in the output table that is created using the Compare Table tool (anything that has an ObjectID < 0). My script was working fine (i.e. it produced the table compare output), until I inserted this Update Cursor code. It's throwing me a RuntimeError: create cursor has failed error. I tested a Search cursor in its place, and that worked fine. I'm thinking there may be a lock of some sort on the data since it was just created, but I'm not sure how to clear that lock. Any ideas?

arcpy.TableCompare_management(orig_queryTable, arcgisTable_cleaned, "UNIQUE_ID", "ATTRIBUTES_ONLY", "IGNORE_SUBTYPES", "", "", "CONTINUE_COMPARE", out_compare_file=compareTxtFile)

sqlExp = """ "ObjectID" < 0 """
with arcpy.da.UpdateCursor(compareTxtFile, "ObjectID", sqlExp) as deleteCursor:
    for row in deleteCursor:

closed as unclear what you're asking by Vince, PolyGeo Aug 11 '15 at 2:37

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    I think deleteRow() doesn't take an argument, so you can just write deleteCursor.deleteRow() rather than deleteCursor.deleteRow(row). – John Aug 10 '15 at 17:02
  • John is correct. Also, why not use the 'OID@' token to grab the ObjectID field? It will always find it by its type (OID). – crmackey Aug 10 '15 at 17:08
  • I edited the question to remove the row from (row) (but the script still throws the same error). As for the ObjectID field, it's not the actual OID field. It's a field that references the tables' being compared ObjectID's so that you can perform a join back to the original data. It's actually just a "long" field. In the output, the "real" OID field created is called "OBJECTID_1." It's a little confusing. – Kristen G. Aug 10 '15 at 17:29
  • @KristenG. Are you running the UpdateCursor on a standalone text file? – ianbroad Aug 10 '15 at 18:00
  • Would you be able to edit your question so that it contains a snippet that works up to the point where the error is thrown (i.e. starts with import arcpy) and the exact wording (including line number) of that error, please? – PolyGeo Aug 11 '15 at 2:35

I think the problem is you cannot use updateCursor on a text file to delete reocrds. Try using it against a dbBASE or geodatabase table instead.

  • I think you're right. I realized that a bit ago and have been messing with my code. I'm using arcpy.TableToTable_conversion to convert it to a gdb table, exactly like you're proposing. – Kristen G. Aug 10 '15 at 21:19

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