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:
<SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;">Runtime</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> error </SPAN><SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;">Traceback</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> </SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">(</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">most recent call last</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">):</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">
</SPAN><SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;">File</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> </SPAN><SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;">"<string>"</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">,</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> line </SPAN><SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;">26</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">,</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> </SPAN><SPAN class="" style="color: #101094; border: 0px; font-size: 13px;">in</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> </SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"><</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">module</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">></SPAN><SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;">SystemError</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">:</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> error </SPAN><SPAN class="" style="color: #101094; border: 0px; font-size: 13px;">return</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> without exception set</SPAN>
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:
<SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;">Runtime</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> error </SPAN><SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;">Traceback</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> </SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">(</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">most recent call last</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">):</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">
</SPAN><SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;">File</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> </SPAN><SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;">"<string>"</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">,</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> line </SPAN><SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;">18</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">,</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> </SPAN><SPAN class="" style="color: #101094; border: 0px; font-size: 13px;">in</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> </SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"><</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">module</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">></SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">
</SPAN><SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;">File</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> </SPAN><SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;">"c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\management.py"</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">,</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">
line </SPAN><SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;">15715</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">,</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> </SPAN><SPAN class="" style="color: #101094; border: 0px; font-size: 13px;">in</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> </SPAN><SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;">CreateTable</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">
</SPAN><SPAN class="" style="color: #101094; border: 0px; font-size: 13px;">raise</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> e </SPAN><SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;">ExecuteError</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">:</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> ERROR </SPAN><SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;">001143</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">:</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> </SPAN><SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;">Background</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> server threw an exception</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">.</SPAN>
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!