[Tutor] Need help with python script

P McCombs mccombs at imperium.org
Mon Aug 4 17:20:41 CEST 2014


Sorry, I missed copying this to the list.

On Aug 4, 2014 8:13 AM, "P McCombs" <mccombs at imperium.org> wrote:
>
>
> On Jul 31, 2014 4:50 PM, "McKinley, Brett D." <BMCKINLEY at mawss.com> wrote:
> >
> > 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:
>
> Does the code you attached execute successfully?
> Are you running this as a tool,  or from the command line?
> Be cautioned that arcpy is outside the scope of this mailing list,  but
it won't have much to do with your questions at first.
>
> >
> >
> > 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.
> >
>
> It is best to try to add one new feature on your own and attach the
result. You will get the best feedback that way.
>
> >
> >
> > Thanks
> >
> > Brett McKinley
> >
> >
> >
> >
> >
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > To unsubscribe or change subscription options:
> >https://mail.python.org/mailman/listinfo/tutor
> >
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140804/2af8ef77/attachment.html>


More information about the Tutor mailing list