I created a script that takes a .tab file and joins it to a shapefile. The script works perfectly but when it finishes, it gives me an unhandled exception which crashes Python.
I don't know what might be causing it but I think I have identify where it's happening. I wanted to ask if someone could help me identify the problem so I can fix it. I'm using ArcPy 10.1 and Python 2.7. I think it's happening in this part. For all the variables I get values prior to this portion of the script. I do the same calculation for other fields so this code repeats itself but for different columns.
#Create and calculate new fields
#Population
if(p == 1):
pop_calc = '!pop_20{}!-!pop_2010!'.format(year)
arcpy.AddField_management(outFeature, "pop_diff","LONG",15,"","","","")
arcpy.CalculateField_management(outFeature,'pop_diff',pop_calc,"PYTHON_9.3")
arcpy.AddField_management(outFeature, "popShare","DOUBLE",15,10,"","","")
popSharedTotal = 0
popFields = 'pop_diff'
with arcpy.da.SearchCursor(fc, popFields)as cursor:
for row in cursor:
popSharedTotal = row[0] + popSharedTotal
arcpy.AddField_management(outFeature, 'temp',"LONG",15,"","","","")
arcpy.CalculateField_management(outFeature,'temp',popSharedTotal,"PYTHON_9.3")
arcpy.CalculateField_management(outFeature,'popShare','[pop_diff]/[temp]',"VB")
arcpy.DeleteField_management(outFeature,'temp')
I can provide the entire script if needed but by commenting sections, this portion is what makes Python not close correctly when done with the script.