[Tutor] Need help with python script

McKinley, Brett D. BMCKINLEY at mawss.com
Thu Jul 31 17:13:23 CEST 2014


I would like to see if someone can help me with a python script.  I'm trying to export a file geodatabase feature class to csv file.  This is what I have so far:

import arcpy
import os
import csv
import domainvalues


def export_to_csv(dataset, output, dialect):
    """Output the data to a CSV file"""
    # create the output writer
    out_writer = csv.writer(open(output, 'wb'), dialect=dialect)
    # return the list of field names and field values
    header, rows = domainvalues.header_and_iterator(dataset)

    # write the field names and values to the csv file
    out_writer.writerow(map(domainvalues._encodeHeader, header))
    for row in rows:
        out_writer.writerow(map(domainvalues._encode, row))

if __name__ == "__main__":
    # Get parameters
    dataset_name = arcpy.GetParameterAsText(0)
    output_file = arcpy.GetParameterAsText(1)
    delim = arcpy.GetParameterAsText(2).lower()
    dialect = 'excel'
    if delim == 'comma':
        pass
    else:
        dialect = 'excel-tab'
    try:
        export_to_csv(dataset_name, output_file, dialect)
    except Exception as err:
        arcpy.AddError('Error: {0}'.format(err))


I would like for the script to export only certain fields and also export only the newest records.  As for now, it's exporting everything.

Thanks
Brett McKinley


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140731/97156129/attachment.html>


More information about the Tutor mailing list