2

I am having problems when using ArcPy with ArcGIS Desktop to add in a set number of rows into a .dbf table.

What should I do to prevent these errors?

Here is a sample code that gives me errors:

##########setup###########
import arcpy, os
from arcpy import env


##########parameters##########

ws =  r'C:\Users\ddsouth\Documents\Python_tests'
env.workspace = ws

newFile = "adding_table_rows_test_1"
newFileFull = os.path.join(ws, newFile) + ".dbf"

###########code###############

#create the table
arcpy.CreateTable_management(ws, newFile)
arcpy.AddField_management(newFileFull, "RouteName", "TEXT", "", "", 15)
arcpy.AddField_management(newFileFull, "DepotName", "TEXT", "", "", 15)

#edit the table
cursor = arcpy.da.InsertCursor(newFile, ["ROUTENAME"])

for q in range (0,10):
    cursor.insertRow((str(1),))
del cursor

print "Completed."

The creation of the table goes fine the first time, then when it comes to the edit portion I get the following error message:

Runtime error 
Traceback (most recent call last):
  File "<string>", line 26, in <module>
SystemError: error return without exception set

Then if I run the program again, I get a different error, this time during the creation of the table, even if I have the "Overwrite the outputs of geoprocessing operations" option selected:

Runtime error  Traceback (most recent call last):   File "<string>", line 18, in <module>   File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\management.py", line 15715, in CreateTable     raise e ExecuteError: ERROR 001143: Background server threw an exception.

I also noticed that while the tables I created appear in ArcCatalog, they do not appear in Windows Explorer, there is only a LOCK file while ArcMap is open.

What should be done?

  • Your insert should include extra parentheses - cursor.insertRow((str(1))) – Midavalo Apr 18 '17 at 17:31
  • Thanks for the response! I had not noticed I had done that wrong. However I changed that and it did not affect the errors I was getting. – David South Apr 18 '17 at 18:00
  • you might need a comma after str(1) because its a tuple – ziggy Apr 18 '17 at 19:00
  • the problem still persists after changing it to a tuple – David South Apr 19 '17 at 20:39
  • 1
    SOLVED: The problem seems to have been with not having the .dbf extension at the end of the filename, ArcPy was assuming I was using a Info table instead of a dBASE table. Works fine now. Thank you everyone for the help! – David South Apr 25 '17 at 0:08
1

As indicated in the comments, you need to create a tuple for your insertRow. Currently your input is a string.

>>> ((str(1)))
'1'
>>> ((str(1),))
('1',)
>>> 

New code:

for q in range (0,10):
    cursor.insertRow((str(1),))
  • I changed it to a tuple and I still get "SystemError: error return without exception set" – David South Apr 19 '17 at 20:38

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.