<?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: List of fields in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/list-of-fields/m-p/418279#M32850</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Gaspar, what you're getting is a list of field objects, which, when printed out, looks like gibberish.&amp;nbsp; As jamesfreddyc wrote above, you need to access the name property of each field object.&amp;nbsp; You can condense this by using list comprehension:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
if "fieldname" in [f.name for f in arcpy.ListFields(featureclass)]:
&amp;nbsp;&amp;nbsp;&amp;nbsp; #do something
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Lists and dictionaries are extremely useful, so it's good to get familiar with them &lt;/SPAN&gt;&lt;A href="https://docs.python.org/2/tutorial/datastructures.html" rel="nofollow noopener noreferrer" target="_blank"&gt;https://docs.python.org/2/tutorial/datastructures.html&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 18:55:36 GMT</pubDate>
    <dc:creator>AdamCox1</dc:creator>
    <dc:date>2021-12-11T18:55:36Z</dc:date>
    <item>
      <title>List of fields</title>
      <link>https://community.esri.com/t5/python-questions/list-of-fields/m-p/418275#M32846</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hallo!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I need to check if a feature class includes a field called 'unwanted_field' and then delete it. I've been trying to accomplish that with an if statement on a field list gained by the arcpy.ListFields tool, but with no success. If I type in my 10.2.1 ArcMap Python window next code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.ListFields('my_feature_class')&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I get the following result:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[&amp;lt;Field object at 0x57483b0[0x623f860]&amp;gt;, &amp;lt;Field object at 0x5748290[0x623ff20]&amp;gt;, &amp;lt;Field object at 0x57485b0[0x623fd10]&amp;gt;, &amp;lt;Field object at 0x114465d0[0x623ff80]&amp;gt;, &amp;lt;Field object at 0x5742ff0[0x623fda0]&amp;gt;, &amp;lt;Field object at 0x587d570[0x623f650]&amp;gt;, &amp;lt;Field object at 0x11446670[0x623fa10]&amp;gt;, &amp;lt;Field object at 0x11446630[0x623fea8]&amp;gt;]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;even though&amp;nbsp; my_feature_class includes 8 fields named: OBJECTID, SHAPE, Shape_Length, etc.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What am I doing wrong?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Gašper&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 May 2014 13:33:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-of-fields/m-p/418275#M32846</guid>
      <dc:creator>GasperZupancic</dc:creator>
      <dc:date>2014-05-15T13:33:08Z</dc:date>
    </item>
    <item>
      <title>Re: List of fields</title>
      <link>https://community.esri.com/t5/python-questions/list-of-fields/m-p/418276#M32847</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
for fld in arcpy.ListFields('my_feature_class'):
&amp;nbsp; if fld.name == 'unwanted_field':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'add field delete code here
&amp;nbsp;&amp;nbsp; &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 18:55:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-of-fields/m-p/418276#M32847</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-12-11T18:55:28Z</dc:date>
    </item>
    <item>
      <title>Re: List of fields</title>
      <link>https://community.esri.com/t5/python-questions/list-of-fields/m-p/418277#M32848</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You are doing nothing wrong, it just is printing the location on the harddrive of each field, instead of the name.&amp;nbsp; If you need to retrieve the actual name of the field, you need to use the .baseName or .aliasName method on each field.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;More on that can be found getting field attributes here: &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//018z0000004n000000" rel="nofollow noopener noreferrer" target="_blank"&gt;http://resources.arcgis.com/en/help/main/10.2/index.html#//018z0000004n000000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you are writing in the interative python window, you'd probably want something like this if you wanted to just delete the "unwanted_field".&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
fieldlist = arcpy.ListFields('my_feature_class')
 
for field in fieldlist:
&amp;nbsp; if field.baseName == "unwanted_field":
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.DeleteField_management('my_feature_class", field)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helps&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Edit: Oops looks like James beat me to it.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 18:55:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-of-fields/m-p/418277#M32848</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2021-12-11T18:55:30Z</dc:date>
    </item>
    <item>
      <title>Re: List of fields</title>
      <link>https://community.esri.com/t5/python-questions/list-of-fields/m-p/418278#M32849</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try something like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
# 1. list fields &lt;SPAN style="font-family:verdana;"&gt;(from &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//018v00000012000000" rel="nofollow noopener noreferrer" target="_blank"&gt;here&lt;/A&gt;)
import&lt;/SPAN&gt;&lt;SPAN style="font-family:verdana;"&gt; arcpy&amp;nbsp; 
featureclass = "c:/data/municipal.gdb/hospitals" 
field_names = [f.name for f in arcpy.ListFields(featureclass)] &lt;/SPAN&gt;

&lt;SPAN style="font-family:verdana;"&gt;# 2. another method
import arcpy
lstflds = arcpy.ListFields("yourfeatureclass")
for fld in lstflds:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if fld.name == "somefield":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.DeleteField_management("yourfeatureclass", "somefield")

# 3. simpler, if you know your feature class; no need to check field name, you provide it
arcpy.DeleteField_management("yourfeatureclass", "somefield")
&lt;/SPAN&gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 18:55:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-of-fields/m-p/418278#M32849</guid>
      <dc:creator>Zeke</dc:creator>
      <dc:date>2021-12-11T18:55:33Z</dc:date>
    </item>
    <item>
      <title>Re: List of fields</title>
      <link>https://community.esri.com/t5/python-questions/list-of-fields/m-p/418279#M32850</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Gaspar, what you're getting is a list of field objects, which, when printed out, looks like gibberish.&amp;nbsp; As jamesfreddyc wrote above, you need to access the name property of each field object.&amp;nbsp; You can condense this by using list comprehension:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
if "fieldname" in [f.name for f in arcpy.ListFields(featureclass)]:
&amp;nbsp;&amp;nbsp;&amp;nbsp; #do something
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Lists and dictionaries are extremely useful, so it's good to get familiar with them &lt;/SPAN&gt;&lt;A href="https://docs.python.org/2/tutorial/datastructures.html" rel="nofollow noopener noreferrer" target="_blank"&gt;https://docs.python.org/2/tutorial/datastructures.html&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 18:55:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-of-fields/m-p/418279#M32850</guid>
      <dc:creator>AdamCox1</dc:creator>
      <dc:date>2021-12-11T18:55:36Z</dc:date>
    </item>
    <item>
      <title>Re: List of fields</title>
      <link>https://community.esri.com/t5/python-questions/list-of-fields/m-p/418280#M32851</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think we had an overkill of responses for this thread.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 May 2014 14:01:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-of-fields/m-p/418280#M32851</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2014-05-15T14:01:11Z</dc:date>
    </item>
    <item>
      <title>Re: List of fields</title>
      <link>https://community.esri.com/t5/python-questions/list-of-fields/m-p/418281#M32852</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I think we had an overkill of responses for this thread.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt;Yeah, I think they all happened simultaneously too.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 May 2014 14:03:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-of-fields/m-p/418281#M32852</guid>
      <dc:creator>AdamCox1</dc:creator>
      <dc:date>2014-05-15T14:03:44Z</dc:date>
    </item>
    <item>
      <title>Re: List of fields</title>
      <link>https://community.esri.com/t5/python-questions/list-of-fields/m-p/418282#M32853</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Tkank you all!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 May 2014 04:57:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-of-fields/m-p/418282#M32853</guid>
      <dc:creator>GasperZupancic</dc:creator>
      <dc:date>2014-05-19T04:57:33Z</dc:date>
    </item>
  </channel>
</rss>

