<?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: How to delete fields based off of another layer's fields?  in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-delete-fields-based-off-of-another-layer-s/m-p/556933#M43538</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A couple of things:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First, In your code snippet, it looks like your using lower case "i" for the field variable in your loop, but you're using an upper case "I" on the DeleteField_management command.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Second, the DeleteField_management command wants a list of field names to delete, not a single field.&amp;nbsp; It would be more efficient for you to first construct a list of field names to delete, then delete them all with a single call to DeleteField_management.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Take a look at the examples here:&amp;nbsp; &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/delete-field.htm"&gt; DeleteField_management​&lt;/A&gt;​&lt;/P&gt;&lt;P&gt;Example 3 shows how to programatically build lists of fields then delete them. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 28 Apr 2016 16:28:30 GMT</pubDate>
    <dc:creator>EarlSarow</dc:creator>
    <dc:date>2016-04-28T16:28:30Z</dc:date>
    <item>
      <title>How to delete fields based off of another layer's fields?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-delete-fields-based-off-of-another-layer-s/m-p/556929#M43534</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to compare the fields of two layers and delete any that are different. This is the code that I thought would work, but it returns RuntimeError: Object: Error in executing tool. Any ideas?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;List = arcpy.ListFields("Layer 1")&lt;BR /&gt;x = arcpy.ListFields("Layer 2")&lt;/P&gt;&lt;P&gt;for i in x:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if i in List:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print i&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.DeleteField_management("Layer 2", I)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Apr 2016 14:57:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-delete-fields-based-off-of-another-layer-s/m-p/556929#M43534</guid>
      <dc:creator>KellyZiegenfuss2</dc:creator>
      <dc:date>2016-04-28T14:57:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete fields based off of another layer's fields?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-delete-fields-based-off-of-another-layer-s/m-p/556930#M43535</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Kelly, &lt;/P&gt;&lt;P&gt;Have you tried running it?&amp;nbsp; If so, did you get any errors?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Apr 2016 15:07:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-delete-fields-based-off-of-another-layer-s/m-p/556930#M43535</guid>
      <dc:creator>MitchHolley1</dc:creator>
      <dc:date>2016-04-28T15:07:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete fields based off of another layer's fields?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-delete-fields-based-off-of-another-layer-s/m-p/556931#M43536</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="http://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/delete-field.htm" title="http://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/delete-field.htm"&gt;Delete Field—Help | ArcGIS for Desktop&lt;/A&gt; &lt;/P&gt;&lt;P&gt;From there, there is some things you should add to your script, like the workspace.&amp;nbsp; it might be a wise idea to check that you are deleting from a table view and that the table isn't open in the project.&amp;nbsp; Also, you are running this from within a project too, since it won't work as a standalone script.&amp;nbsp; So any information that can elaborate on the conditions that you are running this script under might be useful.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Apr 2016 15:09:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-delete-fields-based-off-of-another-layer-s/m-p/556931#M43536</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-04-28T15:09:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete fields based off of another layer's fields?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-delete-fields-based-off-of-another-layer-s/m-p/556932#M43537</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As Dan says, first include the env.workspace to change to this workspace.&lt;/P&gt;&lt;P&gt;Then ListFields returns a fields object, which has various properties (or attributes).&lt;/P&gt;&lt;P&gt;so :&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14618565911578650 jive_text_macro" data-renderedposition="86_8_1332_16" jivemacro_uid="_14618565911578650"&gt;&lt;P&gt;fldsFirst = [f.name for f in arcpy.ListFields(fc)]&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;will give you a list of the field names.&lt;/P&gt;&lt;P&gt;Do this on both then run your other loop to delete the fields in the second fc.&lt;/P&gt;&lt;P&gt;Back up your original fc's first, you never know when your routine might do something you may not have intended.&lt;/P&gt;&lt;P&gt;All this assuming you are running this in an IDE, not a python window inside ArcMap or wherever.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Apr 2016 15:18:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-delete-fields-based-off-of-another-layer-s/m-p/556932#M43537</guid>
      <dc:creator>NeilAyres</dc:creator>
      <dc:date>2016-04-28T15:18:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete fields based off of another layer's fields?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-delete-fields-based-off-of-another-layer-s/m-p/556933#M43538</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A couple of things:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First, In your code snippet, it looks like your using lower case "i" for the field variable in your loop, but you're using an upper case "I" on the DeleteField_management command.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Second, the DeleteField_management command wants a list of field names to delete, not a single field.&amp;nbsp; It would be more efficient for you to first construct a list of field names to delete, then delete them all with a single call to DeleteField_management.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Take a look at the examples here:&amp;nbsp; &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/delete-field.htm"&gt; DeleteField_management​&lt;/A&gt;​&lt;/P&gt;&lt;P&gt;Example 3 shows how to programatically build lists of fields then delete them. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Apr 2016 16:28:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-delete-fields-based-off-of-another-layer-s/m-p/556933#M43538</guid>
      <dc:creator>EarlSarow</dc:creator>
      <dc:date>2016-04-28T16:28:30Z</dc:date>
    </item>
  </channel>
</rss>

