<?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: How to access just one specific value in a row in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-access-just-one-specific-value-in-a-row/m-p/499694#M39259</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;yep, ye ol' list comprehension, certainly worth a vote!&amp;nbsp; Personally, I would have preferred compiling a dictionary to have a key lookup for any value I like, ah but this user needs to learn how to fish 1st, what do you think?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Happy Friday, Chris!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;PS- my 1000th post, for what that is worth!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 28 Mar 2014 17:12:09 GMT</pubDate>
    <dc:creator>T__WayneWhitley</dc:creator>
    <dc:date>2014-03-28T17:12:09Z</dc:date>
    <item>
      <title>How to access just one specific value in a row</title>
      <link>https://community.esri.com/t5/python-questions/how-to-access-just-one-specific-value-in-a-row/m-p/499689#M39254</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am looking for a way to compare&amp;nbsp; values in my fieldA. Specifically I would like to compare my last value to the one in the row above. I used GetCount to know how many rows I have. So for example if GetCount returns that there is 10 rows, I would like to compare numeric values from row 10 and 9 in a fieldA. For some reason I have problem with accessing values with a specific index: I can access all values but not just one. I tried to modify code from &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//002z0000001q000000"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#//002z0000001q000000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;with arcpy.da.SearchCursor(fc, ['fieldA',]) as cursor:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(row)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;to something like&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;with arcpy.da.SearchCursor(fc, ['fieldA',]) as cursor:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myValue=row[10]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print (myValue)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;but it does not work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Did anybody figured out how to access just one specific value, not all of them?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Mar 2014 18:44:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-access-just-one-specific-value-in-a-row/m-p/499689#M39254</guid>
      <dc:creator>JoannaLaroussi</dc:creator>
      <dc:date>2014-03-27T18:44:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to access just one specific value in a row</title>
      <link>https://community.esri.com/t5/python-questions/how-to-access-just-one-specific-value-in-a-row/m-p/499690#M39255</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello jlaroussi, try this thread: &lt;/SPAN&gt;&lt;A href="http://forums.arcgis.com/threads/105463-Alternative-to-Using-getValue-with-Data-Access-Module"&gt;http://forums.arcgis.com/threads/105463-Alternative-to-Using-getValue-with-Data-Access-Module&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Mar 2014 19:04:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-access-just-one-specific-value-in-a-row/m-p/499690#M39255</guid>
      <dc:creator>AdamCox1</dc:creator>
      <dc:date>2014-03-27T19:04:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to access just one specific value in a row</title>
      <link>https://community.esri.com/t5/python-questions/how-to-access-just-one-specific-value-in-a-row/m-p/499691#M39256</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Not the most elegant solution, but since you only have 10 rows...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;i = 0
lastvalue = []
with arcpy.da.SearchCursor(fc, ["fieldA"]) 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; lastvalue.append(row[0])&amp;nbsp; # keep track of all your values so you have a lookup table.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if i == 9: # this is the last row in the table, i.e. row 10
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if row[0] == lastvalue[i-1]:&amp;nbsp; # compare the last row in the table to row 9.
&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; print('current row equals the previous row')

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i += 1&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:56:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-access-just-one-specific-value-in-a-row/m-p/499691#M39256</guid>
      <dc:creator>EdFarrell</dc:creator>
      <dc:date>2021-12-11T21:56:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to access just one specific value in a row</title>
      <link>https://community.esri.com/t5/python-questions/how-to-access-just-one-specific-value-in-a-row/m-p/499692#M39257</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;jlaroussi...just a quick note, at the 10.1 help reference you list, there is a section "Accessing and setting field values" and the very 1st sample code shows the following (shortened here) - I think you need to pay careful attention to the comment 'Access and print the row values by index position.' (which appears in my browser not to be justified left with the other comments so maybe you missed it or didn't fully understand):&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
with arcpy.da.SearchCursor(fc, ['STATE_NAME', 'POP2000']) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
 # Access and print the row values by index position.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #&amp;nbsp;&amp;nbsp; state name: row[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #&amp;nbsp;&amp;nbsp; population: row[1]
&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; print('{0} has a population of {1}'.format(row[0], row[1]))
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The 'index position' is in this example the position within the list ['STATE_NAME', 'POP2000']; in other words, not related to the rows or fields in your attribute table in the way you may be thinking.&amp;nbsp; The row object returned in each iteration (for row in cursor) is a single pair of state name and population values - so row[10] would have no meaning, unless of course you had 11 field names in the list to return values for....in that case, for a particular row, you'd ask for the last value from the 11th field name you specify with row[10].&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, if you wanted to make this dynamic, returning only the last 2 row values regardless of the number of rows, you could leverage the count you said you are retrieving --- untested code below, but I think you could use that count (also dynamically fetched) something similar to the following:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
# your count value as a var named 'count'
count = arcpy.GetCount.... etc.

with arcpy.da.SearchCursor(fc, ['fieldA']) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row = cursor.next()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for i in range(count):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if i &amp;lt;= count - 2:
&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; print('row {0} has a value of {1}'.format(str(i + 1), row[0]))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row = cursor.next()
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:56:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-access-just-one-specific-value-in-a-row/m-p/499692#M39257</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2021-12-11T21:56:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to access just one specific value in a row</title>
      <link>https://community.esri.com/t5/python-questions/how-to-access-just-one-specific-value-in-a-row/m-p/499693#M39258</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;How about:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;listOfFieldValues = [r[0] for r in arcpy.da.SearchCursor(myTbl, ["FieldA"])]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;numberOfFieldValues = len(listOfFieldValues)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;lastFieldValue = listOfFieldValues[-1]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;secondToLastFieldValue = listOfFieldValues[-2]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Mar 2014 16:25:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-access-just-one-specific-value-in-a-row/m-p/499693#M39258</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2014-03-28T16:25:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to access just one specific value in a row</title>
      <link>https://community.esri.com/t5/python-questions/how-to-access-just-one-specific-value-in-a-row/m-p/499694#M39259</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;yep, ye ol' list comprehension, certainly worth a vote!&amp;nbsp; Personally, I would have preferred compiling a dictionary to have a key lookup for any value I like, ah but this user needs to learn how to fish 1st, what do you think?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Happy Friday, Chris!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;PS- my 1000th post, for what that is worth!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Mar 2014 17:12:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-access-just-one-specific-value-in-a-row/m-p/499694#M39259</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2014-03-28T17:12:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to access just one specific value in a row</title>
      <link>https://community.esri.com/t5/python-questions/how-to-access-just-one-specific-value-in-a-row/m-p/499695#M39260</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;something like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;list =sorted([row.getvalue(fieldname) for row in arcpy.SearchCursor(inputdata,query...fields,sort)])&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print list[-2:]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 29 Mar 2014 01:15:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-access-just-one-specific-value-in-a-row/m-p/499695#M39260</guid>
      <dc:creator>benberman</dc:creator>
      <dc:date>2014-03-29T01:15:20Z</dc:date>
    </item>
  </channel>
</rss>

