So I am working on a custom tool that uses one of the existing fields to make a selection by attribute. For example, say I have a feature called Target Feature and in the feature, the fields were called Field1, Field2, Field3, and Field4. I am trying to get a variable to be set equal to arcpy.ListFields('Target Feature') and then to check if a field name is in that feature. The selection I want wasn't working, no selection was being made actually. Here's what I was leaning towards but it didn't work for me:
<SPAN class="keyword token">import</SPAN> arcpy
fieldList <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFields<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Target Feature'</SPAN><SPAN class="punctuation token">)</SPAN>
fieldName <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'Field3'</SPAN><SPAN class="punctuation token">]</SPAN>
fieldValue <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'%45B%'</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">if</SPAN> fieldName <SPAN class="keyword token">in</SPAN> fieldList<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> fieldValue <SPAN class="keyword token">in</SPAN> fieldName<SPAN class="punctuation token">:</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>SelectLayerByAttribute_management <SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Target Feature'</SPAN><SPAN class="punctuation token">,</SPAN> NEW_SELECION<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Field3 LIKE "</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">"'"</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>fieldValue<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">"'"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
But this isn't working for me. Any help is appreciated!