<?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: if field.name in fieldList in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/if-field-name-in-fieldlist/m-p/53646#M4246</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ben,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The best way would be to to create a boolean variable that you set to true if the field name exists, something like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for fc in fcs:&lt;/P&gt;&lt;P&gt;&amp;nbsp; fieldList = arcpy.ListFields(fc)&lt;/P&gt;&lt;P&gt;&amp;nbsp; fieldExists = false&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for field in fieldList:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if field.name == "CAT":&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldExists = true&lt;/P&gt;&lt;P&gt;&amp;nbsp; if(fieldExists):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword"&gt;print&lt;/SPAN&gt; fc + &lt;SPAN class="string"&gt;" Yes"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="string"&gt;&amp;nbsp; else:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword"&gt;print&lt;/SPAN&gt; fc + &lt;SPAN class="string"&gt;" No"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 23 Sep 2014 08:31:07 GMT</pubDate>
    <dc:creator>AnthonyGiles</dc:creator>
    <dc:date>2014-09-23T08:31:07Z</dc:date>
    <item>
      <title>if field.name in fieldList</title>
      <link>https://community.esri.com/t5/python-questions/if-field-name-in-fieldlist/m-p/53643#M4243</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;I'm trying to do a script that will search a bunch of features and tell me if they contain a certain field name or not:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14114577544569381" jivemacro_uid="_14114577544569381"&gt;
&lt;P&gt;fcs = arcpy.ListFeatureClasses()&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;for fc in fcs:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldList = arcpy.ListFields(fc)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if "CAT" in fieldList:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print fc + " Yes"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print fc + " Nope"&lt;/P&gt;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think I've figured out that I somehow need to tell it is look for "CAT" as a field name in fieldList but I'm not sure how to write it.&lt;/P&gt;&lt;P&gt;I've tried a few things such as:&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14114580163412882" jivemacro_uid="_14114580163412882"&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if "CAT" in fieldList.field.name&lt;/P&gt;

&lt;/PRE&gt;&lt;P&gt;but I haven't hit upon the correct syntax.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you help?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(just thought I'd add that everything comes out as "Nope", which isn't correct, using the above code)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Sep 2014 07:42:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/if-field-name-in-fieldlist/m-p/53643#M4243</guid>
      <dc:creator>BenLeslie1</dc:creator>
      <dc:date>2014-09-23T07:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: if field.name in fieldList</title>
      <link>https://community.esri.com/t5/python-questions/if-field-name-in-fieldlist/m-p/53644#M4244</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ben,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You need to iterate through each of your fields checking them individually, not tested but something like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for fc in fcs:&lt;/P&gt;&lt;P&gt;&amp;nbsp; fieldList = arcpy.ListFields(fc)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for field in fieldList:&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if field.name == "CAT":&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;EM&gt;Do Something.....&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Do Something....&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Sep 2014 07:51:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/if-field-name-in-fieldlist/m-p/53644#M4244</guid>
      <dc:creator>AnthonyGiles</dc:creator>
      <dc:date>2014-09-23T07:51:46Z</dc:date>
    </item>
    <item>
      <title>Re: if field.name in fieldList</title>
      <link>https://community.esri.com/t5/python-questions/if-field-name-in-fieldlist/m-p/53645#M4245</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Anthony but it doesn't quite give me the results I'm looking for..... your answer tells me whether &lt;EM&gt;every&lt;/EM&gt; fieldname in the list is "CAT" or not so the output is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;feature1.shp Nope&lt;/P&gt;&lt;P&gt;feature1.shp Nope&lt;/P&gt;&lt;P&gt;feature1.shp Yes&lt;/P&gt;&lt;P&gt;feature1.shp Nope&lt;/P&gt;&lt;P&gt;feature2.shp Nope&lt;/P&gt;&lt;P&gt;feature2.shp Nope&lt;/P&gt;&lt;P&gt;feature2.shp Nope&lt;/P&gt;&lt;P&gt;feature2.shp Nope&lt;/P&gt;&lt;P&gt;........etc&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I really want is a single yes or no for each feature.&lt;/P&gt;&lt;P&gt;For each feature could I somehow concatenate all the fieldnames into a single string and test that?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Sep 2014 08:15:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/if-field-name-in-fieldlist/m-p/53645#M4245</guid>
      <dc:creator>BenLeslie1</dc:creator>
      <dc:date>2014-09-23T08:15:03Z</dc:date>
    </item>
    <item>
      <title>Re: if field.name in fieldList</title>
      <link>https://community.esri.com/t5/python-questions/if-field-name-in-fieldlist/m-p/53646#M4246</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ben,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The best way would be to to create a boolean variable that you set to true if the field name exists, something like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for fc in fcs:&lt;/P&gt;&lt;P&gt;&amp;nbsp; fieldList = arcpy.ListFields(fc)&lt;/P&gt;&lt;P&gt;&amp;nbsp; fieldExists = false&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for field in fieldList:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if field.name == "CAT":&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldExists = true&lt;/P&gt;&lt;P&gt;&amp;nbsp; if(fieldExists):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword"&gt;print&lt;/SPAN&gt; fc + &lt;SPAN class="string"&gt;" Yes"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="string"&gt;&amp;nbsp; else:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword"&gt;print&lt;/SPAN&gt; fc + &lt;SPAN class="string"&gt;" No"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Sep 2014 08:31:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/if-field-name-in-fieldlist/m-p/53646#M4246</guid>
      <dc:creator>AnthonyGiles</dc:creator>
      <dc:date>2014-09-23T08:31:07Z</dc:date>
    </item>
  </channel>
</rss>

