<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Exporting Records to .CSV.  Problem with Comma data offsets to another field - CODE INCLUDED in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/exporting-records-to-csv-problem-with-comma-data/m-p/363637#M28766</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, that is the format for csv files. You could do some fancy checking and replacing. It looks like from your example that the first intended field is the problem one. You could check if the next value is a year, and if not, replace the comma with a zero length string. That could be prone to error, and you may have the same problem in other fields anyway.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It might be easier to make it a tab delimited or fixed length file. That's what I'd look at, anyway.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 10 Nov 2014 21:45:50 GMT</pubDate>
    <dc:creator>Zeke</dc:creator>
    <dc:date>2014-11-10T21:45:50Z</dc:date>
    <item>
      <title>Exporting Records to .CSV.  Problem with Comma data offsets to another field - CODE INCLUDED</title>
      <link>https://community.esri.com/t5/python-questions/exporting-records-to-csv-problem-with-comma-data/m-p/363636#M28765</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a python script tool that exports records from a feature layer using an (area of interest - aoi).&amp;nbsp; The tool works well, but the problem is that if I have a comma in text in one of the field records, it will break the text after the comma and move it to the next field.&amp;nbsp; The shown below that are highlighted in yellow show records that are offset.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="ExportRecordsOffsetFromFields.jpg" class="jive-image image-1" src="https://community.esri.com/legacyfs/online/28977_ExportRecordsOffsetFromFields.jpg" style="width: 620px; height: 263px;" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am attaching the toolbox along with the script.&amp;nbsp; Is there a way I can fix this issue?&amp;nbsp; I didn't get any help from ESRI.&amp;nbsp; They just forwarded me some links, but I figure I can get some assistance from here.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is a copy of the toolbox and script as an attachment:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the script code itself:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;CODE&amp;gt;&lt;/P&gt;&lt;P&gt;# -*- coding: utf-8 -*-&lt;BR /&gt;'''&lt;BR /&gt;&amp;nbsp;&amp;nbsp; This script will convert a table to an excel spreadsheet. If the third-party&lt;BR /&gt;&amp;nbsp;&amp;nbsp; module xlwt is available, it will use that. Otherwise, it will fall back to&lt;BR /&gt;&amp;nbsp;&amp;nbsp; CSV.&lt;BR /&gt;'''&lt;BR /&gt;# **********************************************************************&lt;BR /&gt;# * 01. Import arcpy Module&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *&lt;BR /&gt;# **********************************************************************&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;import os&lt;BR /&gt;import zipfile&lt;/P&gt;&lt;P&gt;# **********************************************************************&lt;BR /&gt;# * 02. Variable Descriptions&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *&lt;BR /&gt;# **********************************************************************&lt;BR /&gt;# Variable&amp;nbsp;&amp;nbsp;&amp;nbsp; Definition&lt;BR /&gt;#&lt;BR /&gt;# InputDataset&amp;nbsp;&amp;nbsp; Dataset used for input.&lt;BR /&gt;# DataDescription&amp;nbsp; Described properties of the input dataset.&lt;BR /&gt;# FieldNames&amp;nbsp;&amp;nbsp; Field names from table.&lt;BR /&gt;# FileFormat&amp;nbsp;&amp;nbsp; File format of output either CSV or XLS.&lt;BR /&gt;# SelectedFeatures&amp;nbsp; Features that are selected from input dataset.&lt;BR /&gt;# OutputFile&amp;nbsp;&amp;nbsp; Name of the output file.&lt;/P&gt;&lt;P&gt;# **********************************************************************&lt;BR /&gt;# * 03. Prepare Data for Table&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *&lt;BR /&gt;# **********************************************************************&lt;/P&gt;&lt;P&gt;def get_ID_message(ID):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return re.sub('%1|%2', '%s', arcpy.GetIDMessage(ID))&lt;/P&gt;&lt;P&gt;def zipUpFolder(folder, outZipFile):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # zip the data&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; try:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; zip = zipfile.ZipFile(outZipFile, 'w', zipfile.ZIP_DEFLATED)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; zipws(unicode(folder), zip, 'CONTENTS_ONLY')&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; zip.close()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; except RuntimeError:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Delete zip file if exists&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if os.path.exists(outZipFile):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; os.unlink(outZipFile)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; zip = zipfile.ZipFile(outZipFile, 'w', zipfile.ZIP_STORED)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; zipws(unicode(folder), zip, 'CONTENTS_ONLY')&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; zip.close()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Message'&amp;nbsp; Unable to compress zip file contents.'&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddWarning(get_ID_message(86133))&lt;/P&gt;&lt;P&gt;def zipws(path, zip, keep):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; path = os.path.normpath(path)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # os.walk visits every subdirectory, returning a 3-tuple&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #&amp;nbsp; of directory name, subdirectories in it, and filenames&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #&amp;nbsp; in it.&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (dirpath, dirnames, filenames) in os.walk(path):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Iterate over every filename&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for file in filenames:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Ignore .lock files&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if not file.endswith('.lock'):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #arcpy.AddMessage('Adding %s...' % os.path.join(path, dirpath, file))&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if keep:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; zip.write(os.path.join(dirpath, file),&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; os.path.join(os.path.basename(path), os.path.join(dirpath, file)[len(path)+len(os.sep):]))&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; zip.write(os.path.join(dirpath, file),&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; os.path.join(dirpath[len(path):], file))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; except Exception as e:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Message '&amp;nbsp;&amp;nbsp;&amp;nbsp; Error adding %s: %s'&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddWarning(get_ID_message(86134) % (file, e[0]))&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return None&lt;/P&gt;&lt;P&gt;def createFolderInScratch(folderName):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # create the folders necessary for the job&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; folderPath = arcpy.CreateUniqueName(folderName, arcpy.env.scratchFolder)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CreateFolder_management(arcpy.env.scratchFolder, os.path.basename(folderPath))&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return folderPath&lt;/P&gt;&lt;P&gt;# Returns a list of column names and an iterator over the same columns&lt;BR /&gt;def header_and_iterator(InputDataset):&lt;/P&gt;&lt;P&gt;# Describe Properties of Input Dataset&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DataDescription = arcpy.Describe(InputDataset)&lt;/P&gt;&lt;P&gt;# Field Name Definitions&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FieldNames = [f.name for f in DataDescription.fields if f.type not in ['Geometry', 'Raster', 'Blob']]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def iterator_for_feature():&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor = arcpy.SearchCursor(InputDataset)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row = cursor.next()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while row:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; yield [getattr(row, col) for col in FieldNames]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row = cursor.next()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del row, cursor&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return FieldNames, iterator_for_feature()&lt;/P&gt;&lt;P&gt;def export_to_xls(dataset, output):&lt;BR /&gt; # Attempt to output to an XLS file. If xmlwt is not available, fall back&lt;BR /&gt; # to CSV. XLWT can be downloaded from &lt;A href="http://pypi.python.org/pypi/xlwt"&gt;http://pypi.python.org/pypi/xlwt&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; try:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; import xlwt&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; except ImportError:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddError('import of xlwt module failed')&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; header, rows = header_and_iterator(dataset)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Make spreadsheet&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; workbook = xlwt.Workbook()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; worksheet = workbook.add_sheet(os.path.split(dataset)[1])&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Set Up Header Row and Freeze Panes&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; header_style = xlwt.easyxf('font: bold on; align: horiz center')&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for index, colheader in enumerate(header):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; worksheet.write(0, index, colheader.replace('.','_'))&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; worksheet.set_panes_frozen(True)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; worksheet.set_horz_split_pos(1)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; worksheet.set_remove_splits(True)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Write Rows&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for rowidx, row in enumerate(rows):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for colindex, col in enumerate(row):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; worksheet.write(rowidx+1, colindex, col)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Completed Workbook&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; workbook.save(output)&lt;/P&gt;&lt;P&gt;if __name__ == '__main__':&lt;/P&gt;&lt;P&gt;# ***********************************&lt;BR /&gt; # * 01. Input Parameters&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *&lt;BR /&gt; # ***********************************&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; InputDataset&amp;nbsp; = arcpy.GetParameterAsText(0) # Input Dataset&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; aoi&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = arcpy.GetParameter(1) # Select Area of Interest&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FileFormat&amp;nbsp;&amp;nbsp;&amp;nbsp; = arcpy.GetParameterAsText(2) # Output format (CSV or XLS)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; OutputFolder&amp;nbsp; = createFolderInScratch('FlatFiles')&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; OutputZipFile = arcpy.GetParameterAsText(3)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for i,ds in enumerate(InputDataset.split(';')):&lt;/P&gt;&lt;P&gt;# ***********************************&lt;BR /&gt; # * 02. Select Dataset By Location&amp;nbsp; *&lt;BR /&gt; # ***********************************&lt;BR /&gt; arcpy.SelectLayerByLocation_management(ds, 'INTERSECT', aoi)&lt;/P&gt;&lt;P&gt;# Selected Features from Input Dataset&lt;BR /&gt; SelectedFeatures = arcpy.MakeFeatureLayer_management(ds)&lt;/P&gt;&lt;P&gt;# ***********************************&lt;BR /&gt; # * 03. Format&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *&lt;BR /&gt; # ***********************************&lt;/P&gt;&lt;P&gt;# Comma Separated Values (CSV)&lt;BR /&gt; if FileFormat == 'CSV':&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fields = ''&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for field in arcpy.ListFields(SelectedFeatures):&lt;BR /&gt;&amp;nbsp; if field.name.lower() not in ['shape']:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fields = fields + field.name + ';'&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fields = fields.rstrip(';')&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage('Export to CSV')&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Create CSV File&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OutputFile = os.path.join(OutputFolder,'c%s_%s.csv' % (str(i).zfill(2), ds.split(os.sep)[-1]))&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.ExportXYv_stats(SelectedFeatures,fields,'COMMA',OutputFile,'ADD_FIELD_NAMES')&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Excel File (XLS)&lt;BR /&gt; elif FileFormat == 'XLS':&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try:&lt;BR /&gt;&amp;nbsp;&amp;nbsp; # Create XLS File&lt;BR /&gt;&amp;nbsp; OutputFile = os.path.join(OutputFolder,'x%s_%s.xls' % (str(i).zfill(2), ds.split(os.sep)[-1]))&lt;BR /&gt;&amp;nbsp; export_to_xls(ds, OutputFile)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; except:&lt;BR /&gt;&amp;nbsp; import traceback&lt;BR /&gt;&amp;nbsp; arcpy.AddError(traceback.format_exc())&lt;BR /&gt; else:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; raise ValueError('Don\'t know how to export to %r' % FileFormat)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; zipUpFolder(OutputFolder, OutputZipFile)&lt;/P&gt;&lt;P&gt;&amp;lt;/CODE&amp;gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Nov 2014 15:53:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/exporting-records-to-csv-problem-with-comma-data/m-p/363636#M28765</guid>
      <dc:creator>IanPeebles</dc:creator>
      <dc:date>2014-11-10T15:53:30Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting Records to .CSV.  Problem with Comma data offsets to another field - CODE INCLUDED</title>
      <link>https://community.esri.com/t5/python-questions/exporting-records-to-csv-problem-with-comma-data/m-p/363637#M28766</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, that is the format for csv files. You could do some fancy checking and replacing. It looks like from your example that the first intended field is the problem one. You could check if the next value is a year, and if not, replace the comma with a zero length string. That could be prone to error, and you may have the same problem in other fields anyway.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It might be easier to make it a tab delimited or fixed length file. That's what I'd look at, anyway.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Nov 2014 21:45:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/exporting-records-to-csv-problem-with-comma-data/m-p/363637#M28766</guid>
      <dc:creator>Zeke</dc:creator>
      <dc:date>2014-11-10T21:45:50Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting Records to .CSV.  Problem with Comma data offsets to another field - CODE INCLUDED</title>
      <link>https://community.esri.com/t5/python-questions/exporting-records-to-csv-problem-with-comma-data/m-p/363638#M28767</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;you could use the python csv library to create the file.&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.python.org/2/library/csv.html" title="https://docs.python.org/2/library/csv.html"&gt;13.1. csv — CSV File Reading and Writing — Python 2.7.8 documentation&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;using a search cursor to format your data appropriately.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Nov 2014 22:03:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/exporting-records-to-csv-problem-with-comma-data/m-p/363638#M28767</guid>
      <dc:creator>DallasShearer</dc:creator>
      <dc:date>2014-11-10T22:03:17Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting Records to .CSV.  Problem with Comma data offsets to another field - CODE INCLUDED</title>
      <link>https://community.esri.com/t5/python-questions/exporting-records-to-csv-problem-with-comma-data/m-p/363639#M28768</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think the problem with that would be in the formatting of data. There are potentially &lt;EM&gt;‌n&lt;/EM&gt;‌ number of commas in &lt;EM&gt;‌n&lt;/EM&gt;‌ number of fields. Not to say it couldn't be done, but it wouldn't be a very efficient process.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Nov 2014 01:44:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/exporting-records-to-csv-problem-with-comma-data/m-p/363639#M28768</guid>
      <dc:creator>Zeke</dc:creator>
      <dc:date>2014-11-12T01:44:30Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting Records to .CSV.  Problem with Comma data offsets to another field - CODE INCLUDED</title>
      <link>https://community.esri.com/t5/python-questions/exporting-records-to-csv-problem-with-comma-data/m-p/363640#M28769</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If it were me I would fix the datasource first.&amp;nbsp; I could understand a comment field that I *MIGHT* allow commas into it, but probably not because it leads to situations you are in now.&amp;nbsp; So fix the thing that is creating the .csv datasource so that it doesn't allow commas to be inserted.&amp;nbsp; That'd be the optimal thing to do.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If not an option then I'd have a separate process that ran to removes commas and convert them into tabs instead.&amp;nbsp; You will still have to do a bunch of gymnastics to find the specific scenario(s) that you want to use to do the replace.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;...which is why it's best to juts fix the source data.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;
&lt;P&gt;I have a python script tool that exports records from a feature layer using an (area of interest - aoi).&amp;nbsp; The tool works well, but the problem is that if I have a comma in text in one of the field records&lt;/P&gt;
&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is where I'd focus my first effort.&amp;nbsp; When it's a Feature Class (before you run your tool), remove any commas in any of the fields.&amp;nbsp; But again, why are you letting them into the data in the first place?&amp;nbsp; Control that process and you don't need to deal with this problem.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Nov 2014 13:38:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/exporting-records-to-csv-problem-with-comma-data/m-p/363640#M28769</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2014-11-12T13:38:08Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting Records to .CSV.  Problem with Comma data offsets to another field - CODE INCLUDED</title>
      <link>https://community.esri.com/t5/python-questions/exporting-records-to-csv-problem-with-comma-data/m-p/363641#M28770</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I agree with @Dallas Shearer.&amp;nbsp; You can use the Python &lt;EM&gt;csv&lt;/EM&gt; library.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The CSV format allows for escaping special characters, so you can have commas in a field.&amp;nbsp; You would quote that field, as in:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;field 1, "This, field has, commas", Field 3&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There is a way to handle fields containing quotes as well.&amp;nbsp; It gets a little messy if you have an assortment of such punctuation, but the &lt;EM&gt;csv&lt;/EM&gt; library handles it for you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's a couple of links:&lt;/P&gt;&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/7571642/writing-escape-characters-to-a-csv-file-in-python" title="https://stackoverflow.com/questions/7571642/writing-escape-characters-to-a-csv-file-in-python"&gt;Writing Escape Characters to a Csv File in Python - Stack Overflow&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/10451842/how-to-escape-comma-and-double-quote-at-same-time-for-csv-file" title="https://stackoverflow.com/questions/10451842/how-to-escape-comma-and-double-quote-at-same-time-for-csv-file"&gt;java - How to escape comma and double quote at same time for CSV file? - Stack Overflow&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One of the contributors to one of those threads also had a good suggestion:&amp;nbsp; If you want your CSV to be compatible with Excel, take one of those strings, copy it into Excel and save it out as CSV.&amp;nbsp; Then you will know how Excel wants it formatted.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Nov 2014 21:59:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/exporting-records-to-csv-problem-with-comma-data/m-p/363641#M28770</guid>
      <dc:creator>ElleryChan</dc:creator>
      <dc:date>2014-11-13T21:59:28Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting Records to .CSV.  Problem with Comma data offsets to another field - CODE INCLUDED</title>
      <link>https://community.esri.com/t5/python-questions/exporting-records-to-csv-problem-with-comma-data/m-p/363642#M28771</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In similar situations in the past, I just resorted to using the pipe symbol or vertical bar as the field separator.&amp;nbsp; Although I have seen crazy data where people use commas, colons, semicolons, and slashes in places they shouldn't be; I seldom run across people using vertical bars in free-form text.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Nov 2014 22:05:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/exporting-records-to-csv-problem-with-comma-data/m-p/363642#M28771</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2014-11-13T22:05:57Z</dc:date>
    </item>
  </channel>
</rss>

