<?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 Export an attribute table to .txt using arcpy. in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/export-an-attribute-table-to-txt-using-arcpy/m-p/10997#M910</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This seems like a no-brainer, perhaps I'm missing something. I can easily export tables to .txt format using the the Arcmap interface, but can't do so using arcpy. I have tried the table to table conversion function but this supports every format but a simple .txt file. Is there a work around? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Fred&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 29 Oct 2013 21:22:34 GMT</pubDate>
    <dc:creator>FredKellner1</dc:creator>
    <dc:date>2013-10-29T21:22:34Z</dc:date>
    <item>
      <title>Export an attribute table to .txt using arcpy.</title>
      <link>https://community.esri.com/t5/python-questions/export-an-attribute-table-to-txt-using-arcpy/m-p/10997#M910</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This seems like a no-brainer, perhaps I'm missing something. I can easily export tables to .txt format using the the Arcmap interface, but can't do so using arcpy. I have tried the table to table conversion function but this supports every format but a simple .txt file. Is there a work around? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Fred&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Oct 2013 21:22:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-an-attribute-table-to-txt-using-arcpy/m-p/10997#M910</guid>
      <dc:creator>FredKellner1</dc:creator>
      <dc:date>2013-10-29T21:22:34Z</dc:date>
    </item>
    <item>
      <title>Re: Export an attribute table to .txt using arcpy.</title>
      <link>https://community.esri.com/t5/python-questions/export-an-attribute-table-to-txt-using-arcpy/m-p/10998#M911</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Fred,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You're right that .TXT is not a supported output format in the Table to Table conversion tool. If you work with a featureclass instead of a table the "&lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//005p0000003v000000" rel="nofollow noopener noreferrer" target="_blank"&gt;Export Feature Attribute to ASCII (Spatial Statistics)&lt;/A&gt;&lt;SPAN&gt;" would be an option.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If not than you can use the snippet below I found on stack exchange:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://gis.stackexchange.com/questions/17933/export-table-to-x-y-z-ascii-file-via-arcpy" rel="nofollow noopener noreferrer" target="_blank"&gt;http://gis.stackexchange.com/questions/17933/export-table-to-x-y-z-ascii-file-via-arcpy&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy,csv

&lt;STRONG&gt;table =r'c:\path\to\table'
outfile = r'c:\path\to\output\ascii\text\file'&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/STRONG&gt;

#--first lets make a list of all of the fields in the table
fields = arcpy.ListFields(table)
field_names = [field.name for field in fields]

with open(outfile,'wb') as f:
&amp;nbsp;&amp;nbsp;&amp;nbsp; w = csv.writer(f)
&amp;nbsp;&amp;nbsp;&amp;nbsp; #--write all field names to the output file
&amp;nbsp;&amp;nbsp;&amp;nbsp; w.writerow(field_names)

&amp;nbsp;&amp;nbsp;&amp;nbsp; #--now we make the search cursor that will iterate through the rows of the table
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in arcpy.SearchCursor(table):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; field_vals = [row.getValue(field.name) for field in fields]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; w.writerow(field_vals)
&amp;nbsp;&amp;nbsp;&amp;nbsp; del row
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Please note that things may go wrong with binary (blob) fields and perhaps with Null values as well.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Kind regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Xander&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:28:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-an-attribute-table-to-txt-using-arcpy/m-p/10998#M911</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2021-12-10T20:28:33Z</dc:date>
    </item>
    <item>
      <title>Re: Export an attribute table to .txt using arcpy.</title>
      <link>https://community.esri.com/t5/python-questions/export-an-attribute-table-to-txt-using-arcpy/m-p/10999#M912</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Xander, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for you input that snippet from GIS stack exchange was just what I needed!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Fred&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Oct 2013 13:27:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-an-attribute-table-to-txt-using-arcpy/m-p/10999#M912</guid>
      <dc:creator>FredKellner1</dc:creator>
      <dc:date>2013-10-30T13:27:08Z</dc:date>
    </item>
  </channel>
</rss>

