I'm working with a script that converts a CSV file to a DBF and then uses the Business Analyst extension to create an XML file that is used for a Gap Report. The script will SOMETIMES work successfully, but after a successful run I have never been able to get it to run a second time immediately after the first successful run.
During early testing, I was able to close ArcMap after a successful run, restart and then get another successful run, but after 3 successful runs, I now get the error every time that I run the script, even after a reboot.
Initially, I thought that it was a problem with the InsertCursor code that converted the CSV to DBF, but the full error seems to point to something else. When I get the error, the DBF file is created successfully, but it seems like the software is unable to convert the DBF to an XML file. One reason could be that the DBF becomes locked. How do I make sure that the DBF is not locked by the previous code when I try to use it to create the XML?
The line of code that is failing is just one line, but the DBF is obviously being created from the code that completes before this line: arcpy.CreateProfileByImportFromTable_ba(sSimmonsDBF, "TAP", "COUNT", sPathProTarget)
Here's the error message: [INDENT][/INDENT]Creating output folders... [INDENT][/INDENT]Finished creating output folders... [INDENT][/INDENT]Importing CSV to DBF... [INDENT][/INDENT]Finished importing CSV to DBF... [INDENT][/INDENT]Creating target profile ... [INDENT][/INDENT]Traceback (most recent call last): [INDENT][/INDENT]File "C:\My Output Data\script.py", line 154, in <module> [INDENT][/INDENT]arcpy.CreateProfileByImportFromTable_ba(sSimmonsDBF, "TAP", "COUNT", sPathProTarget) [INDENT][/INDENT]File "C:\Program Files\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes\Business Analyst Tools.tbx", line 3491, in CreateProfileByImportFromTable [INDENT][/INDENT]AttributeError: 'NoneType' object has no attribute 'CreateProfileByImportFromTable_ba'
for i in range(76): print i line = inf.readline() print line if i > 9: l = len(line) f = line.find('(') value = line[f+1:l] value = value.replace(')','') value = value.replace('"','') tokens = string.split(value,',') row = rows.newRow() row.TAP=tokens[0] row.BASE=float(tokens[1])*1000 row.XTRA=float(tokens[2]) row.COUNT=float(tokens[3])*1000 rows.insertRow(row)
inf.close() del rows del inf arcpy.AddMessage("Finished importing CSV to DBF...") print arcpy.GetMessages()
We're using Python 2.6 with ArcGIS 10. It seems like this could be related to a Python bug (http://bugs.python.org/issue5762) that other people have experience in different circumstances (not with ArcGIS), but being new to this, I'm not sure.