ExportXYV with standalone script doesn't work

Discussion created by lanman31337 on Apr 2, 2014
Latest reply on Apr 15, 2014 by lanman31337
I'm so close - it writes the txt file or csv, writes the field names, but doesn't write any of the field data.  Where am I going wrong?  These are coverages, and it works using arctoolbox from within

print "Connecting to your project, please wait..."
import arcpy
from arcpy import env

mxdPath = r'C:\Projects\test\test-03112014.mxd'
md = arcpy.mapping.MapDocument(mxdPath)
ws = "C:\\Projects\\test\\tables\\"
df = arcpy.mapping.ListDataFrames(md)[0]
targetGroupLayer = arcpy.mapping.ListLayers(md, "interchange_bolivar", df)[0]
tables = arcpy.ListTables()
for tables in targetGroupLayer:
    fieldname = [ for f in arcpy.ListFields(tables.dataSource)]
    td = tables.dataSource
    ext = ".txt"
    filename = (ws + + ext)
         arcpy.ExportXYv_stats(td, fieldname, "SPACE", filename, "ADD_FIELD_NAMES")
         print arcpy.GetMessages()
del md

Here is the error message:

Failed to execute (ExportXYv).
Failed at Wed Apr 02 15:24:01 2014 (Elapsed Time: 1.00 seconds)
Executing: ExportXYv C:\Projects\test\Mine_Maps\BMR_DATA\Bolivar\data\db\db\region.r110 FID;Shape;AREA;PERIMETER;R110#;R110-ID SPACE "db region.r110.txt" ADD_FIELD_NAMES
Start Time: Wed Apr 02 15:24:01 2014
Running script ExportXYv...
Writing Results to ASCII File....

Traceback (most recent call last):
  File "c:\program files (x86)\arcgis\desktop10.1\ArcToolbox\Scripts\", line 159, in <module>
    export = setupXYV()
  File "c:\program files (x86)\arcgis\desktop10.1\ArcToolbox\Scripts\", line 49, in setupXYV
    outFieldNames = outFieldNames)
  File "c:\program files (x86)\arcgis\desktop10.1\ArcToolbox\Scripts\", line 129, in exportXYV
    formatValue = LOCALE.format(localeDict[field], value)
  File "C:\Python27\ArcGIS10.1\lib\", line 190, in format
    return _format(percent, value, grouping, monetary, *additional)
  File "C:\Python27\ArcGIS10.1\lib\", line 196, in _format
    formatted = percent % value
TypeError: not all arguments converted during string formatting

Here's the output of TD, fieldname, and filename:

TD - [u'FID', u'Shape', u'AREA', u'PERIMETER', u'R104#', u'R104-ID']
fieldname - C:\Projects\test\Mine_Maps\BMR_DATA\Bolivar\data\a\a\region.r104
filename - a region.r104.txt