<?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: Export file geodatabase table to scv file in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/export-file-geodatabase-table-to-scv-file/m-p/650545#M50631</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think the only problem is you need to add the '.csv' extension to your test file (otherwise it does not know what file type to open). This will only work if you have ArcGIS 10.1 though since it uses the data access module. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I should also add that in the above script you created the function, but you did not run it. The line that actually will run this is highlighted in blue. The input variables do not have to be named exactly like they are when you define the function either; Python only cares about what the variables are referencing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
from os import path as p

def TableToCSV(fc,CSVFile):
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; fields = [f.name for f in arcpy.ListFields(fc) if f.type &amp;lt;&amp;gt; 'Geometry']
&amp;nbsp;&amp;nbsp;&amp;nbsp; with open(CSVFile, 'w') as f:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; f.write(','.join(fields)+'\n') #csv headers
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(fc, fields) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&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; f.write(','.join([str(r) for r in row])+'\n')
&amp;nbsp;&amp;nbsp;&amp;nbsp; print 'Created %s Successfully' %p.basename(CSVFile)

if __name__ == '__main__':

&amp;nbsp;&amp;nbsp;&amp;nbsp; fc = r"C:\Test\Test.gdb\Test1"
&amp;nbsp;&amp;nbsp;&amp;nbsp; csv = r"C:\Test\Test1.csv"

&amp;nbsp;&amp;nbsp;&amp;nbsp; TableToCSV(fc, csv)
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 16:44:10 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2021-12-12T16:44:10Z</dc:date>
    <item>
      <title>Export file geodatabase table to scv file</title>
      <link>https://community.esri.com/t5/python-questions/export-file-geodatabase-table-to-scv-file/m-p/650544#M50630</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;How can I export a file geodatabase to csv table using python running a script from inside a map document.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Got the following code from Mathew Coyle off this forum and ran it but it did not work for me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Other ideas? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy from os import path as p fc = "C:\\Test\\Test.gdb\\Test1" CSVFile =&amp;nbsp; "C:\\Test\\Test1" def TableToCSV(fc,CSVFile): &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; fields = [f.name for f in arcpy.ListFields(fc) if f.type &amp;lt;&amp;gt; 'Geometry'] &amp;nbsp;&amp;nbsp;&amp;nbsp; with open(CSVFile, 'w') as f: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; f.write(','.join(fields)+'\n') #csv headers &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(fc, fields) as cursor: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor: &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; f.write(','.join([str(r) for r in row])+'\n') &amp;nbsp;&amp;nbsp;&amp;nbsp; print 'Created %s Successfully' %p.basename(CSVFile)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Mar 2013 21:28:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-file-geodatabase-table-to-scv-file/m-p/650544#M50630</guid>
      <dc:creator>ClaudineSicker</dc:creator>
      <dc:date>2013-03-18T21:28:43Z</dc:date>
    </item>
    <item>
      <title>Re: Export file geodatabase table to scv file</title>
      <link>https://community.esri.com/t5/python-questions/export-file-geodatabase-table-to-scv-file/m-p/650545#M50631</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think the only problem is you need to add the '.csv' extension to your test file (otherwise it does not know what file type to open). This will only work if you have ArcGIS 10.1 though since it uses the data access module. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I should also add that in the above script you created the function, but you did not run it. The line that actually will run this is highlighted in blue. The input variables do not have to be named exactly like they are when you define the function either; Python only cares about what the variables are referencing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
from os import path as p

def TableToCSV(fc,CSVFile):
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; fields = [f.name for f in arcpy.ListFields(fc) if f.type &amp;lt;&amp;gt; 'Geometry']
&amp;nbsp;&amp;nbsp;&amp;nbsp; with open(CSVFile, 'w') as f:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; f.write(','.join(fields)+'\n') #csv headers
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(fc, fields) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&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; f.write(','.join([str(r) for r in row])+'\n')
&amp;nbsp;&amp;nbsp;&amp;nbsp; print 'Created %s Successfully' %p.basename(CSVFile)

if __name__ == '__main__':

&amp;nbsp;&amp;nbsp;&amp;nbsp; fc = r"C:\Test\Test.gdb\Test1"
&amp;nbsp;&amp;nbsp;&amp;nbsp; csv = r"C:\Test\Test1.csv"

&amp;nbsp;&amp;nbsp;&amp;nbsp; TableToCSV(fc, csv)
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:44:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-file-geodatabase-table-to-scv-file/m-p/650545#M50631</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-12T16:44:10Z</dc:date>
    </item>
    <item>
      <title>Re: Export file geodatabase table to scv file</title>
      <link>https://community.esri.com/t5/python-questions/export-file-geodatabase-table-to-scv-file/m-p/650546#M50632</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; I think the only problem is you need to add the '.csv' extension to your test file (otherwise it does not know what file type to open). This will only work if you have ArcGIS 10.1 though since it uses the data access module.&amp;nbsp;&amp;nbsp; &lt;BR /&gt; &lt;BR /&gt;I should also add that in the above script you created the function, but you did not run it. The line that actually will run this is highlighted in blue. The input variables do not have to be named exactly like they are when you define the function either; Python only cares about what the variables are referencing.&amp;nbsp; &lt;BR /&gt; &lt;BR /&gt; &lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
from os import path as p

def TableToCSV(fc,CSVFile):
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; fields = [f.name for f in arcpy.ListFields(fc) if f.type &amp;lt;&amp;gt; 'Geometry']
&amp;nbsp;&amp;nbsp;&amp;nbsp; with open(CSVFile, 'w') as f:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; f.write(','.join(fields)+'\n') #csv headers
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(fc, fields) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&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; f.write(','.join([str(r) for r in row])+'\n')
&amp;nbsp;&amp;nbsp;&amp;nbsp; print 'Created %s Successfully' %p.basename(CSVFile)

if __name__ == '__main__':

&amp;nbsp;&amp;nbsp;&amp;nbsp; fc = r"C:\Test\Test.gdb\Test1"
&amp;nbsp;&amp;nbsp;&amp;nbsp; csv = r"C:\Test\Test1&lt;SPAN style="color:&amp;quot;#FF0000&amp;quot;;"&gt;.csv&lt;/SPAN&gt;"

&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color:&amp;quot;#0000FF&amp;quot;;"&gt;TableToCSV(fc, csv)&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Yup. Forgot to run the function. Thanks. Your my new BFF.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:35:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-file-geodatabase-table-to-scv-file/m-p/650546#M50632</guid>
      <dc:creator>ClaudineSicker</dc:creator>
      <dc:date>2021-12-12T03:35:20Z</dc:date>
    </item>
  </channel>
</rss>

