<?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: Add fields where field names are stored in a list - Python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/add-fields-where-field-names-are-stored-in-a-list/m-p/153209#M11847</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If the only field in an existing feature class is geometry and the feature class is empty, why not delete the feature class and re-create it using a template to have the schemas match rather than going through and enumerating all the fields of another feature class and manually creating each field.&amp;nbsp; Is there some reason you can't delete the existing feature class?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 19 Sep 2018 16:23:54 GMT</pubDate>
    <dc:creator>JoshuaBixby</dc:creator>
    <dc:date>2018-09-19T16:23:54Z</dc:date>
    <item>
      <title>Add fields where field names are stored in a list - Python</title>
      <link>https://community.esri.com/t5/python-questions/add-fields-where-field-names-are-stored-in-a-list/m-p/153206#M11844</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have been working on a tool that does a bunch of stuff, but the piece I am currently stuck on is getting the script to create fields where the field names are stored in a list, and the list is created using an already existing feature class. The idea is that the fields will be identical to the existing feature class in order to run the append tool. Here is what I have so far...I am having a hard time figuring out how to tell the script to create the fields based on the items in the fieldnames list using the types in the fieldtypes list.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;#Get list of fields and parameters from original FC.&lt;/SPAN&gt;
fieldnames &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
fieldtypes &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
fields &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ListFields&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;bound&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; field &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; fields&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldnames&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;append&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;field&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;name&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; field &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; fields&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldtypes&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;append&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;field&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;type&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
fieldnames&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;remove&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"OBJECTID"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
fieldnames&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;remove&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"SHAPE"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
fieldtypes&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;remove&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"OID"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
fieldtypes&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;remove&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Geometry"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
fieldtypes &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"TEXT"&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; x&lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"String"&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt; x &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; x &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; fieldtypes&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
fieldtypes &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"DOUBLE"&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; x&lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Double"&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt; x &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; x &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; fieldtypes&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;#Add fields from list with field types.&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; field &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; fieldnames&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddField_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;newfc&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; field&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;name&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; field&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;type&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;""&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;""&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;""&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;""&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;""&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;""&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;""&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&amp;nbsp; &lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:12:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-fields-where-field-names-are-stored-in-a-list/m-p/153206#M11844</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-11T08:12:23Z</dc:date>
    </item>
    <item>
      <title>Re: Add fields where field names are stored in a list - Python</title>
      <link>https://community.esri.com/t5/python-questions/add-fields-where-field-names-are-stored-in-a-list/m-p/153207#M11845</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why not use &lt;A class="link-titled" href="http://pro.arcgis.com/en/pro-app/tool-reference/data-management/create-feature-class.htm" title="http://pro.arcgis.com/en/pro-app/tool-reference/data-management/create-feature-class.htm"&gt;Create Feature Class—Data Management toolbox | ArcGIS Desktop&lt;/A&gt;&amp;nbsp; and use the template parameter?&amp;nbsp; From what you have said here, I think that would address your need and be simpler.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Sep 2018 16:14:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-fields-where-field-names-are-stored-in-a-list/m-p/153207#M11845</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2018-09-19T16:14:23Z</dc:date>
    </item>
    <item>
      <title>Re: Add fields where field names are stored in a list - Python</title>
      <link>https://community.esri.com/t5/python-questions/add-fields-where-field-names-are-stored-in-a-list/m-p/153208#M11846</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The new feature class already exists, with geometry in it, but nothing else. So I am not really trying to create a new feature class to apply these fields to, it already exists, just in a simple form.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Sep 2018 16:17:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-fields-where-field-names-are-stored-in-a-list/m-p/153208#M11846</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2018-09-19T16:17:30Z</dc:date>
    </item>
    <item>
      <title>Re: Add fields where field names are stored in a list - Python</title>
      <link>https://community.esri.com/t5/python-questions/add-fields-where-field-names-are-stored-in-a-list/m-p/153209#M11847</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If the only field in an existing feature class is geometry and the feature class is empty, why not delete the feature class and re-create it using a template to have the schemas match rather than going through and enumerating all the fields of another feature class and manually creating each field.&amp;nbsp; Is there some reason you can't delete the existing feature class?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Sep 2018 16:23:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-fields-where-field-names-are-stored-in-a-list/m-p/153209#M11847</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2018-09-19T16:23:54Z</dc:date>
    </item>
    <item>
      <title>Re: Add fields where field names are stored in a list - Python</title>
      <link>https://community.esri.com/t5/python-questions/add-fields-where-field-names-are-stored-in-a-list/m-p/153210#M11848</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The `fieldnames` list is a list of strings, so its items do not have properties `name` or `type`. You can access the proper items using the list indices:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; i &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; range&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;len&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;fieldnames&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddField_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;newfc&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; fieldnames&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;i&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; fieldtypes&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;i&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;""&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;""&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;""&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;""&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;""&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;""&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;""&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&amp;nbsp; ‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Better yet, make a dictionary and add both the field name and type to each item in order to concretely associate them.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:12:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-fields-where-field-names-are-stored-in-a-list/m-p/153210#M11848</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-11T08:12:26Z</dc:date>
    </item>
    <item>
      <title>Re: Add fields where field names are stored in a list - Python</title>
      <link>https://community.esri.com/t5/python-questions/add-fields-where-field-names-are-stored-in-a-list/m-p/153211#M11849</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, I want to keep that geometry to append to the feature class that the fields are being pulled from. The geometry is created by dissolving various shapes from another feature class. So the geometry is necessary to import into the current feature class.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Sep 2018 16:28:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-fields-where-field-names-are-stored-in-a-list/m-p/153211#M11849</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2018-09-19T16:28:18Z</dc:date>
    </item>
    <item>
      <title>Re: Add fields where field names are stored in a list - Python</title>
      <link>https://community.esri.com/t5/python-questions/add-fields-where-field-names-are-stored-in-a-list/m-p/153212#M11850</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This appears to have worked perfectly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Sep 2018 16:39:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-fields-where-field-names-are-stored-in-a-list/m-p/153212#M11850</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2018-09-19T16:39:36Z</dc:date>
    </item>
  </channel>
</rss>

