<?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 How to use field name instead or numeric index to find value in row,cursor in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-use-field-name-instead-or-numeric-index-to/m-p/395842#M31265</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am looking for a way to compare fields from two rows from two&amp;nbsp;&lt;SPAN style="color: #4d4d4d; background-color: #fefefe; font-weight: bold;"&gt;SearchCursor&lt;/SPAN&gt; but I would like to use a filed name instead of a numeric index&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;instead of&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;if rowYesterday[1] != rowToday[1]&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;]:&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;is there a way to check&amp;nbsp;&amp;nbsp;for &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if rowYesterday[ 'CODE'] != rowToday['CODE']&amp;nbsp;&lt;SPAN&gt;]:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;This is a simplified version of my source code:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;with arcpy.da.SearchCursor(WASDWSCORDINANCELETTER_Psde3, fieldnames, whereClause) as srcYesterday:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; for rowYesterday in srcYesterday:&lt;BR /&gt; &lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if rowYesterday[1] != rowToday[1] ]:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Do somenting&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 05 Oct 2017 16:37:47 GMT</pubDate>
    <dc:creator>JoseSanchez</dc:creator>
    <dc:date>2017-10-05T16:37:47Z</dc:date>
    <item>
      <title>How to use field name instead or numeric index to find value in row,cursor</title>
      <link>https://community.esri.com/t5/python-questions/how-to-use-field-name-instead-or-numeric-index-to/m-p/395842#M31265</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am looking for a way to compare fields from two rows from two&amp;nbsp;&lt;SPAN style="color: #4d4d4d; background-color: #fefefe; font-weight: bold;"&gt;SearchCursor&lt;/SPAN&gt; but I would like to use a filed name instead of a numeric index&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;instead of&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;if rowYesterday[1] != rowToday[1]&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;]:&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;is there a way to check&amp;nbsp;&amp;nbsp;for &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if rowYesterday[ 'CODE'] != rowToday['CODE']&amp;nbsp;&lt;SPAN&gt;]:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;This is a simplified version of my source code:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;with arcpy.da.SearchCursor(WASDWSCORDINANCELETTER_Psde3, fieldnames, whereClause) as srcYesterday:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; for rowYesterday in srcYesterday:&lt;BR /&gt; &lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if rowYesterday[1] != rowToday[1] ]:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Do somenting&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Oct 2017 16:37:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-use-field-name-instead-or-numeric-index-to/m-p/395842#M31265</guid>
      <dc:creator>JoseSanchez</dc:creator>
      <dc:date>2017-10-05T16:37:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to use field name instead or numeric index to find value in row,cursor</title>
      <link>https://community.esri.com/t5/python-questions/how-to-use-field-name-instead-or-numeric-index-to/m-p/395843#M31266</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Heya Jose,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The help docs for da.Search cursor says:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;SPAN style="color: #4d4d4d; background-color: #fefefe;"&gt;Returns an iterator of tuples. The order of values in the tuple matches the order of fields specified by the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #4d4d4d; background-color: #fefefe; font-size: 14px;"&gt;field_names&lt;/SPAN&gt;&lt;SPAN style="color: #4d4d4d; background-color: #fefefe;"&gt;argument.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;That means that in your case, rowYesterday is a tuple with whatever number of values is in your fieldnames tuple or list. So, unfortunately this won't work:&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; rowYesterday&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'CODE'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;!=&lt;/SPAN&gt; rowToday&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'CODE'&lt;/SPAN&gt;&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;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;because rowYesterday is a tuple with no idea what 'CODE' means.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now for the good news. You can look up the 'CODE' value in your rowYesterday tuple by getting CODE's index value from your fieldnames list and then using that to access the value from your rowYesterday tuple. To do that, the syntax would be:&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;rowYesterday&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;fieldnames&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;index&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'CODE'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The .index('value') method returns the index (position) value of that string in your list of field names. So, it's not exactly what you were going for but should produce the desired result.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Micah&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Oct 2017 16:52:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-use-field-name-instead-or-numeric-index-to/m-p/395843#M31266</guid>
      <dc:creator>MicahBabinski</dc:creator>
      <dc:date>2017-10-05T16:52:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to use field name instead or numeric index to find value in row,cursor</title>
      <link>https://community.esri.com/t5/python-questions/how-to-use-field-name-instead-or-numeric-index-to/m-p/395844#M31267</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you really want to work with search cursor rows as dictionaries instead of tuples, you can insert a line to create a dictionary with each iteration:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;with&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SearchCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;fc&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; flds&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; cur&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; row &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; cur&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;k&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;v &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; k&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;v &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; zip&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;cur&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;fields&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;row&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="comment token"&gt;# or row = dict(zip(cur.fields,row))&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&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;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are more ideas in a blog post on the old ArcPy Cafe site:&amp;nbsp; &lt;A class="link-titled" href="https://arcpy.wordpress.com/2012/07/12/getting-arcpy-da-rows-back-as-dictionaries/" title="https://arcpy.wordpress.com/2012/07/12/getting-arcpy-da-rows-back-as-dictionaries/" rel="nofollow noopener noreferrer" target="_blank"&gt;Getting arcpy.da rows back as dictionaries | ArcPy Café&lt;/A&gt; .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dictionary comprehensions are quite quick, but there is still overhead for creating a dictionary with each iteration.&amp;nbsp; How much of an impact that overhead has on your script depends on what else you are doing within each iteration.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It would be quite handy if ArcPy cursors were implemented as ordered dictionaries, or at least supported them.&amp;nbsp; I bring the issue up from time to time with product management, but it just seems the community and customers as a whole aren't calling for it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 18:07:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-use-field-name-instead-or-numeric-index-to/m-p/395844#M31267</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-11T18:07:02Z</dc:date>
    </item>
  </channel>
</rss>

