<?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: Alternative to Using 'getValue' with Data Access Module in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/alternative-to-using-getvalue-with-data-access/m-p/227942#M17681</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Opps, I'm sorry Mike. That was a function of arcpy.SearchCursor (not arcpy.da.SearchCursor).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can try something like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;cur=arcpy.da.SearchCursor(fc, "*")
c=0 #counter
d={} #dictionary used to call the index for a given field name
for field in cur.fields:
&amp;nbsp;&amp;nbsp;&amp;nbsp; d[field]=c
&amp;nbsp;&amp;nbsp;&amp;nbsp; c+=1

for row in cur:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print row[d['SITE_ID']]&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Let me know if that works!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 11:06:13 GMT</pubDate>
    <dc:creator>JoshuaChisholm</dc:creator>
    <dc:date>2021-12-11T11:06:13Z</dc:date>
    <item>
      <title>Alternative to Using 'getValue' with Data Access Module</title>
      <link>https://community.esri.com/t5/python-questions/alternative-to-using-getvalue-with-data-access/m-p/227939#M17678</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;With the arcpy.da module, we cannot use the getValue method on the row object as we can in arcpy.SearchCursor:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;for row in arcpy.SearchCursor(fc):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.getValue("SITE_ID")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;We can, however, index over the columns for the row object:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;with arcpy.da.SearchCursor(fc, "*") as cursor:
 for row in cursor:
&amp;nbsp; print row[1]&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I want to use the data access module because it cuts my processing time by almost a half. Indexing over columns on the row object doesn't really work for me because I am using this on an excel spreasheet where users may move columns around. I prefer to pull the heading name as I can with getValue. Is there a way to do this in the da module?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Mar 2014 17:22:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/alternative-to-using-getvalue-with-data-access/m-p/227939#M17678</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2014-03-27T17:22:44Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative to Using 'getValue' with Data Access Module</title>
      <link>https://community.esri.com/t5/python-questions/alternative-to-using-getvalue-with-data-access/m-p/227940#M17679</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think you might be able to refer to it directly. For example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;with arcpy.da.SearchCursor(fc, "*") as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.SITE_ID&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Good luck!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:06:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/alternative-to-using-getvalue-with-data-access/m-p/227940#M17679</guid>
      <dc:creator>JoshuaChisholm</dc:creator>
      <dc:date>2021-12-11T11:06:08Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative to Using 'getValue' with Data Access Module</title>
      <link>https://community.esri.com/t5/python-questions/alternative-to-using-getvalue-with-data-access/m-p/227941#M17680</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I think you might be able to refer to it directly. For example:&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;with arcpy.da.SearchCursor(fc, "*") as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.SITE_ID&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;Good luck!&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks Jochua, but I've tested that as well and I am retunring the same error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;AttributeError: 'tuple' object has no attribute SITE_ID'&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There must we a way to do this without having to index like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;with arcpy.da.SearchCursor(fc, "*") as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[2]&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:06:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/alternative-to-using-getvalue-with-data-access/m-p/227941#M17680</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2021-12-11T11:06:10Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative to Using 'getValue' with Data Access Module</title>
      <link>https://community.esri.com/t5/python-questions/alternative-to-using-getvalue-with-data-access/m-p/227942#M17681</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Opps, I'm sorry Mike. That was a function of arcpy.SearchCursor (not arcpy.da.SearchCursor).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can try something like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;cur=arcpy.da.SearchCursor(fc, "*")
c=0 #counter
d={} #dictionary used to call the index for a given field name
for field in cur.fields:
&amp;nbsp;&amp;nbsp;&amp;nbsp; d[field]=c
&amp;nbsp;&amp;nbsp;&amp;nbsp; c+=1

for row in cur:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print row[d['SITE_ID']]&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Let me know if that works!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:06:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/alternative-to-using-getvalue-with-data-access/m-p/227942#M17681</guid>
      <dc:creator>JoshuaChisholm</dc:creator>
      <dc:date>2021-12-11T11:06:13Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative to Using 'getValue' with Data Access Module</title>
      <link>https://community.esri.com/t5/python-questions/alternative-to-using-getvalue-with-data-access/m-p/227943#M17682</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think it would be easiest to get the index by the name using the built in list index property:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
with arcpy.da.SearchCursor(fc, '*') as cur:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print row[cur.fields.index('SITE_ID')]
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It would actually more efficient to not have the index in the loop:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
with arcpy.da.SearchCursor(fc, '*') as cur:
&amp;nbsp;&amp;nbsp;&amp;nbsp; ind = cur.fields.index('SITE_ID')
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print row[ind]
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This way it does not have to find the index inside each iteration since the index will not change.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:06:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/alternative-to-using-getvalue-with-data-access/m-p/227943#M17682</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-11T11:06:15Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative to Using 'getValue' with Data Access Module</title>
      <link>https://community.esri.com/t5/python-questions/alternative-to-using-getvalue-with-data-access/m-p/227944#M17683</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;We did &lt;/SPAN&gt;&lt;A href="http://arcpy.wordpress.com/2012/07/12/getting-arcpy-da-rows-back-as-dictionaries/" rel="nofollow noopener noreferrer" target="_blank"&gt;a Blog post on this some time ago&lt;/A&gt;&lt;SPAN&gt;. Are you only accessing a single column? In your example, that appears to be the case. If you know you're just grabbing a certain set of column values, you can specify them when you open the cursor and then you know what index they'll be at. So you'd be best off doing this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
with arcpy.da.SearchCursor(fc, 'SITE_ID') as cur:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print row[0]&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;or&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
with arcpy.da.SearchCursor(fc, ['SITE_ID', 'OTHER_FIELD']) as cur:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print row[0], row[1]&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;etc.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:06:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/alternative-to-using-getvalue-with-data-access/m-p/227944#M17683</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2021-12-11T11:06:18Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative to Using 'getValue' with Data Access Module</title>
      <link>https://community.esri.com/t5/python-questions/alternative-to-using-getvalue-with-data-access/m-p/227945#M17684</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;ah, thank you Jason, didn't see that before...wow, and that's a slick one-liner in the def function:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;yield dict(zip(colnames, row))&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Lots to read and learn...and relearn.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Wayne&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Mar 2014 17:29:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/alternative-to-using-getvalue-with-data-access/m-p/227945#M17684</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2014-03-28T17:29:15Z</dc:date>
    </item>
  </channel>
</rss>

