<?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 to .TXT file include domain values in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/export-to-txt-file-include-domain-values/m-p/1196048#M65069</link>
    <description>&lt;P&gt;That is the python code that iterates through an existing table and prints the field values.&lt;/P&gt;&lt;P&gt;How/where did that table come from?&amp;nbsp; Statistics? Summary?.....&amp;nbsp; I can't seem to create a similar table that keeps the domains for testing.&lt;/P&gt;&lt;P&gt;However it is generated, one option is to export/save it to a stand alone text file INSTEAD of a FGDB table, then search cursor the text file for the print part.&amp;nbsp; Stand alone text files aren't in a GDB, so they don't carry the domains with them.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 26 Jul 2022 18:02:44 GMT</pubDate>
    <dc:creator>RhettZufelt</dc:creator>
    <dc:date>2022-07-26T18:02:44Z</dc:date>
    <item>
      <title>Export to .TXT file include domain values</title>
      <link>https://community.esri.com/t5/python-questions/export-to-txt-file-include-domain-values/m-p/1195998#M65066</link>
      <description>&lt;P&gt;I have already created a series of scripts to sort thru my GDB and produce infrastructure statistics. I have developed one script to run all of the scripts and export the results to a series of .TXT files:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import sys
import os.path

arcpy.env.transferDomains = True

orig = sys.stdout
with open(os.path.join("Z:\Operations\Maps and Records\Infrastructure Counts Stats\DATA EXPORT", "eJOINT_USE_INVENTORY.txt"), "wb") as f:
    sys.stdout = f
    try:
        execfile("JOINT_USE_COUNTS_NEW.py", {})
    finally:
        sys.stdout = orig&lt;/LI-CODE&gt;&lt;P&gt;The issue I am having is when this exports the File GDB Table to a .TXT value, the domain code is exported. I need to have the domain description when the data is exported to the .TXT file. I have verified that the domain is assigned to the specific field.&lt;/P&gt;&lt;P&gt;Thank You&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jul 2022 16:44:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-to-txt-file-include-domain-values/m-p/1195998#M65066</guid>
      <dc:creator>ModernElectric</dc:creator>
      <dc:date>2022-07-26T16:44:19Z</dc:date>
    </item>
    <item>
      <title>Re: Export to .TXT file include domain values</title>
      <link>https://community.esri.com/t5/python-questions/export-to-txt-file-include-domain-values/m-p/1196017#M65067</link>
      <description>&lt;P&gt;so, what does the code that actually exports the table look like?&amp;nbsp; What tool is it using&lt;/P&gt;&lt;P&gt;all I see here is standard python writing to a text file.&amp;nbsp; arcpy is where the domains would be handled.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jul 2022 17:21:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-to-txt-file-include-domain-values/m-p/1196017#M65067</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2022-07-26T17:21:19Z</dc:date>
    </item>
    <item>
      <title>Re: Export to .TXT file include domain values</title>
      <link>https://community.esri.com/t5/python-questions/export-to-txt-file-include-domain-values/m-p/1196027#M65068</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;## CENTURY LINK CONTACTS - PREPARE AND PRINT STATS
print("## CENTURY LINK - JOINT USE - COUNTS ##")
fc = "C:\Users\cwafstet\Documents\GIS WORKING FILES LOCAL\ELECTRIC\MEWCo ELECTRIC SYSTEM - DATA PREP.gdb\STATS_JU_CENTURYLINK"
total = 0
fields = ['CHARGE_TYPE','FREQUENCY']
with arcpy.da.SearchCursor(fc,fields) as cursor:
	for row in cursor:
		total += row[1]
		print "There are {} features for {}".format(row[1],row[0])&lt;/LI-CODE&gt;&lt;P&gt;This is the python script the creates the statistics and write it to a File GDB Table. I verify the domain is added to the field within ArcCatalog. The field with the domain added is CHARGE_TYPE. When the data is printed to the Python Idle screen AND/OR the .TXT file, the code for the domain is displayed instead of the domain description.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ModernElectric_0-1658856623531.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/46832i91B53C4A1663B283/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ModernElectric_0-1658856623531.png" alt="ModernElectric_0-1658856623531.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;ArcCatalog: CHARGE_TYPE field showing the Domain Description&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ModernElectric_1-1658856652358.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/46834iB28CE13B4D70639C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ModernElectric_1-1658856652358.png" alt="ModernElectric_1-1658856652358.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;.TXT exported file showing the domain code. What is circled in red, the goal is to have the domain description instead.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jul 2022 17:32:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-to-txt-file-include-domain-values/m-p/1196027#M65068</guid>
      <dc:creator>ModernElectric</dc:creator>
      <dc:date>2022-07-26T17:32:01Z</dc:date>
    </item>
    <item>
      <title>Re: Export to .TXT file include domain values</title>
      <link>https://community.esri.com/t5/python-questions/export-to-txt-file-include-domain-values/m-p/1196048#M65069</link>
      <description>&lt;P&gt;That is the python code that iterates through an existing table and prints the field values.&lt;/P&gt;&lt;P&gt;How/where did that table come from?&amp;nbsp; Statistics? Summary?.....&amp;nbsp; I can't seem to create a similar table that keeps the domains for testing.&lt;/P&gt;&lt;P&gt;However it is generated, one option is to export/save it to a stand alone text file INSTEAD of a FGDB table, then search cursor the text file for the print part.&amp;nbsp; Stand alone text files aren't in a GDB, so they don't carry the domains with them.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jul 2022 18:02:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-to-txt-file-include-domain-values/m-p/1196048#M65069</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2022-07-26T18:02:44Z</dc:date>
    </item>
    <item>
      <title>Re: Export to .TXT file include domain values</title>
      <link>https://community.esri.com/t5/python-questions/export-to-txt-file-include-domain-values/m-p/1197310#M65094</link>
      <description>&lt;P&gt;Edited to fix the domain dictionary.&lt;/P&gt;&lt;P&gt;----&lt;/P&gt;&lt;P&gt;Put the corresponding values into a dictionary: domain_dict = {150: 'Contact', 151:'Guy', 152:'Riser', ...}&lt;/P&gt;&lt;P&gt;then do a dictionary lookup for the value in the SearchCursor:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with arcpy.da.SearchCursor(fc,fields) as cursor:
	for row in cursor:
	    total += row[1]
            dv = domain_dict.get(row[0], 'Unknown') # &amp;lt;- gets the domain value name here or assignes 'Unknown' as the default value
	    print "There are {} features for {}".format(row[1],dv)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;... if you have a lot of values- you can maybe dynamically create the domain dict, but the key would need to be the number somehow if the domain is a 'Contact': Contact' instead of a 150: 'Contact'.&amp;nbsp; This example is for setting the key as an index 0, 1, 2, etc, but you may be able to get away with using domain.codeValues directly if the domain is 150: 'CONTACT' format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;domains = arcpy.da.ListDomains("path to your .gdb")
domain_dict ={}

for domain in domains:
    print('Domain name: {0}'.format(domain.name))
    if domain.name == 'THE NAME OF THE DOMAIN FOR THAT FIELD':
        if domain.domainType == 'CodedValue':
            for i, v in enumerate(domain.codedValues.values()):
                domain_dict[i] = v&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jul 2022 12:52:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-to-txt-file-include-domain-values/m-p/1197310#M65094</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-07-29T12:52:54Z</dc:date>
    </item>
  </channel>
</rss>

