Can you post the full code? I have included this function in many scripts for creating spreadsheets for the non-GIS people in my office. Here is what it looks like in one of my scripts:
import arcpy, os, sys, traceback
arcpy.env.workspace = 'G:\\Data\\Geodatabase\\Cedar_County.mdb'
arcpy.env.overwriteOutput = True
infeat = 'G:\\Data\\Geodatabase\\Cedar_County.mdb\\SOILS\\SOILS_BY_PARCEL'
outputpath = 'O:\\CSR_Report\\'
dissolveoutpath = 'G:\\PROJECTS\\Cedar\\Soils\\testing\\'
outfeat = dissolveoutpath + 'dissolve.shp'
out_table = outputpath + 'CSR_Report.csv'
dfield = "PID"
statfield = "WEIGHTED_AVERAGE_CSR FIRST; SUM_ FIRST"
dfield = ['PID']
expression = "!FIRST_WEIG!"
expression2 = "!FIRST_SUM_!"
dropfields = ["FIRST_WEIG", "FIRST_SUM_"]
try:
print "Starting Dissolve..."
arcpy.Dissolve_management(infeat, outfeat, dfield, statfield,
"MULTI_PART", "DISSOLVE_LINES")
arcpy.AddField_management(outfeat, "AVE_CSR", "FLOAT")
arcpy.CalculateField_management(outfeat, "AVE_CSR", expression,
"PYTHON")
arcpy.AddField_management(outfeat, "TOTAL_CSR", "FLOAT")
arcpy.CalculateField_management(outfeat, "TOTAL_CSR", expression2,
"PYTHON")
print 'Cleaning table'
arcpy.DeleteField_management(outfeat, dropfields)
print 'Dissolve finished, now converting table to CSV'
fieldnames = [f.name for f in arcpy.ListFields(outfeat)]
arcpy.ExportXYv_stats(outfeat, fieldnames, "COMMA", out_table,
"ADD_FIELD_NAMES")
print 'CSR table created sucessfully'
except:
arcpy.AddError(arcpy.GetMessages(2))