<?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: Using python to replace subtypes with descriptions in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/using-python-to-replace-subtypes-with-descriptions/m-p/178618#M13722</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I just figured out between each I need to have .replace instead of just a .&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 29 Oct 2014 14:30:24 GMT</pubDate>
    <dc:creator>DirkPeterson</dc:creator>
    <dc:date>2014-10-29T14:30:24Z</dc:date>
    <item>
      <title>Using python to replace subtypes with descriptions</title>
      <link>https://community.esri.com/t5/python-questions/using-python-to-replace-subtypes-with-descriptions/m-p/178617#M13721</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a workflow that wil use a definition query to select a subset of point data that will be exported from SDE to a 3rd party.&amp;nbsp; One of the attributes is a subtype where there are 14 subtypes.&amp;nbsp; When I export the data, the subtype remains as a number rather than a description.&amp;nbsp; What I need to do is come up with a python expression to replace all of the different subtype numbers with the descriptions.&amp;nbsp; I have found where I can replace subtype with the description, but how do I do all of them at once?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is what I came up with:&lt;/P&gt;&lt;P&gt;!Fieldname!.replace("subtype1","description1").("subtype2","description2")........("subtype14","description14)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I run this, I get a ERROR 000539&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm new to Python so any help would be appreciated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Oct 2014 14:07:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-python-to-replace-subtypes-with-descriptions/m-p/178617#M13721</guid>
      <dc:creator>DirkPeterson</dc:creator>
      <dc:date>2014-10-29T14:07:02Z</dc:date>
    </item>
    <item>
      <title>Re: Using python to replace subtypes with descriptions</title>
      <link>https://community.esri.com/t5/python-questions/using-python-to-replace-subtypes-with-descriptions/m-p/178618#M13722</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I just figured out between each I need to have .replace instead of just a .&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Oct 2014 14:30:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-python-to-replace-subtypes-with-descriptions/m-p/178618#M13722</guid>
      <dc:creator>DirkPeterson</dc:creator>
      <dc:date>2014-10-29T14:30:24Z</dc:date>
    </item>
    <item>
      <title>Re: Using python to replace subtypes with descriptions</title>
      <link>https://community.esri.com/t5/python-questions/using-python-to-replace-subtypes-with-descriptions/m-p/178619#M13723</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What is the field type? If it's numeric (since you mention number), you can't put a string into it. Otherwise, I don't think you can run a multiple replace in one line like that; at least, I've never seen it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Assuming this is in Field Calculator, set the parser to Python and check Show Codeblock. In Pre-Logic Script Code, enter something like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def DoThis(myField):&amp;nbsp; 


&amp;nbsp;&amp;nbsp;&amp;nbsp; if myfield == '1':


&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; val = 'description1'


&amp;nbsp;&amp;nbsp;&amp;nbsp; elif myfield == '2':


&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; val = 'description2'


&amp;nbsp;&amp;nbsp;&amp;nbsp; elif myfield == '3':


&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; val = 'description3'


&amp;nbsp;&amp;nbsp;&amp;nbsp; .


&amp;nbsp;&amp;nbsp;&amp;nbsp; .


&amp;nbsp;&amp;nbsp;&amp;nbsp; .


&amp;nbsp;&amp;nbsp;&amp;nbsp; elif myfield == '14':


&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; val = 'description14'


&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&amp;nbsp;&amp;nbsp;&amp;nbsp; 


&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; val = 'somedefaultvalue' 


&amp;nbsp;&amp;nbsp;&amp;nbsp; return val



&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the Fieldname = box, enter&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

DoThis(!Fieldname!)



&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This assumes that Fieldname is text. If not, you'll have to add a new text field and calculate that instead.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are other ways to handle this; you could add subtypes or domains to your new feature class, for example, but the above should work ok.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:09:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-python-to-replace-subtypes-with-descriptions/m-p/178619#M13723</guid>
      <dc:creator>Zeke</dc:creator>
      <dc:date>2021-12-11T09:09:36Z</dc:date>
    </item>
  </channel>
</rss>

