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_5" 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? Thank you!
Solved! Go to Solution.
Curtis, thank you for the effort you have taken to help me. The code now works! Giving it the .dbf extension seems to have done the trick!
Thank you so much to everyone who has helped!
dBASE would work just fine