<?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 get the value of a field from the first row without looping? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-get-the-value-of-a-field-from-the-first-row/m-p/76461#M6211</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So to circle back, for the laymen, which approach would be the best to use?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 05 Apr 2017 18:40:57 GMT</pubDate>
    <dc:creator>RustyRex</dc:creator>
    <dc:date>2017-04-05T18:40:57Z</dc:date>
    <item>
      <title>How to get the value of a field from the first row without looping?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-the-value-of-a-field-from-the-first-row/m-p/76452#M6202</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Hi all,&lt;/P&gt;&lt;P&gt;I am wondering how to get the value a field frorm the first row without looping through all the rows?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Feb 2015 18:45:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-the-value-of-a-field-from-the-first-row/m-p/76452#M6202</guid>
      <dc:creator>SaidAkif</dc:creator>
      <dc:date>2015-02-26T18:45:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the value of a field from the first row without looping?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-the-value-of-a-field-from-the-first-row/m-p/76453#M6203</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You still have to start a loop, but you can break out of it and kill the cursor at any time:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN class="kn" style="color: #0000ff;"&gt;import&lt;/SPAN&gt;&lt;SPAN style="font-size: 9pt; line-height: 12pt;"&gt; &lt;/SPAN&gt;&lt;SPAN class="nn" style="font-size: 9pt; line-height: 12pt;"&gt;arcpy&lt;/SPAN&gt;
&lt;SPAN style="font-family: monospace;"&gt; &lt;/SPAN&gt;
&lt;SPAN class="n" style="font-size: 9pt; line-height: 12pt;"&gt;fc&lt;/SPAN&gt;&lt;SPAN style="font-size: 9pt; line-height: 12pt;"&gt; &lt;/SPAN&gt;&lt;SPAN class="o" style="font-size: 9pt; line-height: 12pt;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="font-size: 9pt; line-height: 12pt;"&gt; &lt;/SPAN&gt;&lt;SPAN class="s" style="color: #a31515;"&gt;'c:/data/base.gdb/features'&lt;/SPAN&gt;

&lt;SPAN style="color: #008000; font-size: 9pt; line-height: 12pt;"&gt;# Open a cursor on some fields in a table&lt;/SPAN&gt;
&lt;SPAN class="k" style="color: #0000ff;"&gt;with&lt;/SPAN&gt;&lt;SPAN style="font-size: 9pt; line-height: 12pt;"&gt; &lt;/SPAN&gt;&lt;SPAN class="n" style="font-size: 9pt; line-height: 12pt;"&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class="o" style="font-size: 9pt; line-height: 12pt;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n" style="font-size: 9pt; line-height: 12pt;"&gt;da&lt;/SPAN&gt;&lt;SPAN class="o" style="font-size: 9pt; line-height: 12pt;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n" style="font-size: 9pt; line-height: 12pt;"&gt;SearchCursor&lt;/SPAN&gt;&lt;SPAN class="p" style="font-size: 9pt; line-height: 12pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="n" style="font-size: 9pt; line-height: 12pt;"&gt;fc&lt;/SPAN&gt;&lt;SPAN class="p" style="font-size: 9pt; line-height: 12pt;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="font-size: 9pt; line-height: 12pt;"&gt; &lt;/SPAN&gt;&lt;SPAN class="p" style="font-size: 9pt; line-height: 12pt;"&gt;[&lt;/SPAN&gt;&lt;SPAN class="s" style="color: #a31515;"&gt;'OID@'&lt;/SPAN&gt;&lt;SPAN class="p" style="font-size: 9pt; line-height: 12pt;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="font-size: 9pt; line-height: 12pt;"&gt; &lt;/SPAN&gt;&lt;SPAN class="s" style="color: #a31515;"&gt;'SHAPE@AREA'&lt;/SPAN&gt;&lt;SPAN class="p" style="font-size: 9pt; line-height: 12pt;"&gt;])&lt;/SPAN&gt;&lt;SPAN style="font-size: 9pt; line-height: 12pt;"&gt; &lt;/SPAN&gt;&lt;SPAN class="k" style="color: #0000ff;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 9pt; line-height: 12pt;"&gt; &lt;/SPAN&gt;&lt;SPAN class="n" style="font-size: 9pt; line-height: 12pt;"&gt;cursor&lt;/SPAN&gt;&lt;SPAN class="p" style="font-size: 9pt; line-height: 12pt;"&gt;:&lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt; line-height: 12pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="k" style="color: #0000ff;"&gt;for&lt;/SPAN&gt;&lt;SPAN style="font-size: 9pt; line-height: 12pt;"&gt; &lt;/SPAN&gt;&lt;SPAN class="n" style="font-size: 9pt; line-height: 12pt;"&gt;row&lt;/SPAN&gt;&lt;SPAN style="font-size: 9pt; line-height: 12pt;"&gt; &lt;/SPAN&gt;&lt;SPAN class="ow" style="color: #0000ff;"&gt;in&lt;/SPAN&gt;&lt;SPAN style="font-size: 9pt; line-height: 12pt;"&gt; &lt;/SPAN&gt;&lt;SPAN class="n" style="font-size: 9pt; line-height: 12pt;"&gt;cursor&lt;/SPAN&gt;&lt;SPAN class="p" style="font-size: 9pt; line-height: 12pt;"&gt;:&lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt; line-height: 12pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #0000ff;"&gt;# Do&amp;nbsp; something with the first row of data here
&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;SPAN style="line-height: 12pt; color: #0000ff; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break&lt;/SPAN&gt;
&lt;SPAN style="line-height: 12pt; color: #0000ff; font-size: 9pt;"&gt;del cursor&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN style="font-size: 9pt; line-height: 12pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:57:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-the-value-of-a-field-from-the-first-row/m-p/76453#M6203</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2021-12-10T22:57:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the value of a field from the first row without looping?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-the-value-of-a-field-from-the-first-row/m-p/76454#M6204</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I try and that works&lt;/P&gt;&lt;P&gt;Thanks all of you&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Feb 2015 19:01:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-the-value-of-a-field-from-the-first-row/m-p/76454#M6204</guid>
      <dc:creator>SaidAkif</dc:creator>
      <dc:date>2015-02-26T19:01:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the value of a field from the first row without looping?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-the-value-of-a-field-from-the-first-row/m-p/76455#M6205</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Since the &lt;SPAN style="font-family: courier new,courier;"&gt;arcpy.da.SearchCursor&lt;/SPAN&gt; is an iterable that returns one list per row of the table/cursor, the Python built-in &lt;A href="https://docs.python.org/2/library/functions.html#next" rel="nofollow noopener noreferrer" target="_blank"&gt;next() &lt;/A&gt;function can be used to retrieve the next row, which would be the first row if the cursor was just created or reset.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy&amp;nbsp; 

fc = 'c:/data/base.gdb/features'&amp;nbsp; 

# Open a cursor on some fields in a table&amp;nbsp; 
with arcpy.da.SearchCursor(fc, ['OID@', &lt;A href="mailto:'SHAPE@AREA'" rel="nofollow noopener noreferrer" target="_blank"&gt;'SHAPE@AREA'&lt;/A&gt;]) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; row = next(cursor)
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Do&amp;nbsp; something with the first row of data here

del cursor &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:57:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-the-value-of-a-field-from-the-first-row/m-p/76455#M6205</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-10T22:57:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the value of a field from the first row without looping?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-the-value-of-a-field-from-the-first-row/m-p/76456#M6206</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Or, something very similar, use the SearchCursor next method.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;/PRE&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Cur = arcpy.da.SearchCursor(Feature, [Flds])
row = Cur.next()
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:57:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-the-value-of-a-field-from-the-first-row/m-p/76456#M6206</guid>
      <dc:creator>NeilAyres</dc:creator>
      <dc:date>2021-12-10T22:57:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the value of a field from the first row without looping?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-the-value-of-a-field-from-the-first-row/m-p/76457#M6207</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Or to use a one-liner:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14250458019642839 jive_text_macro" jivemacro_uid="_14250458019642839"&gt;&lt;P&gt;value = arcpy.da.SearchCursor(in_fc, ("YourFieldName",)).next()[0]&lt;/P&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Feb 2015 14:03:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-the-value-of-a-field-from-the-first-row/m-p/76457#M6207</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2015-02-27T14:03:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the value of a field from the first row without looping?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-the-value-of-a-field-from-the-first-row/m-p/76458#M6208</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I try your code Xander and it work perfectly. That is really the easiest way to do it&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for you all guys&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Feb 2015 14:08:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-the-value-of-a-field-from-the-first-row/m-p/76458#M6208</guid>
      <dc:creator>SaidAkif</dc:creator>
      <dc:date>2015-02-27T14:08:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the value of a field from the first row without looping?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-the-value-of-a-field-from-the-first-row/m-p/76459#M6209</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;True, for now and in the ArcPy realm, calling the search cursor's next method will get the same result.&amp;nbsp; I suggested using the built-in next method because of broader changes happening with Python outside of ArcPy.&amp;nbsp; For Python 3 after &lt;A href="https://www.python.org/dev/peps/pep-3114/"&gt;PEP 3114&lt;/A&gt; was approved, it meant the next() iterator method was going away.&amp;nbsp; The &lt;A href="https://www.python.org/dev/peps/pep-3114/#transition-plan"&gt;Transition Plan &lt;/A&gt;for PEP 3114 covers two additional changes needed for moving to Python 3:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Method definitions named next will be renamed to __next__ .&lt;/LI&gt;&lt;LI&gt;Explicit calls to the next method will be replaced with calls to the built-in next function. For example, x.next() will become next(x) .&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The built-in next function was introduced in Python 2.6 to smooth the transition.&amp;nbsp; Since we know that Esri has made the leap to Python 3 with ArcGIS Pro, I suggested an approach using the built-in function.&amp;nbsp; For now, Esri's implementation of the ArcPy Data Access (arcpy.da) module in ArcGIS Pro still includes cursors having explicit next() methods, but I argue the current ArcGIS Pro implementation isn't very pythonic since the explicit next() methods don't add any special functionality beyond simply iterating.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Feb 2015 15:52:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-the-value-of-a-field-from-the-first-row/m-p/76459#M6209</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2015-02-27T15:52:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the value of a field from the first row without looping?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-the-value-of-a-field-from-the-first-row/m-p/76460#M6210</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If the cursor isn't going to be used once and disposed of, using a Python with statement ensures the cursor is reset for its next use.&amp;nbsp; But then again, maybe having the cursor automatically reset isn't what someone wants.&amp;nbsp; Just depends on the situation and need.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Feb 2015 15:55:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-the-value-of-a-field-from-the-first-row/m-p/76460#M6210</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2015-02-27T15:55:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the value of a field from the first row without looping?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-the-value-of-a-field-from-the-first-row/m-p/76461#M6211</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So to circle back, for the laymen, which approach would be the best to use?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Apr 2017 18:40:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-the-value-of-a-field-from-the-first-row/m-p/76461#M6211</guid>
      <dc:creator>RustyRex</dc:creator>
      <dc:date>2017-04-05T18:40:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the value of a field from the first row without looping?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-the-value-of-a-field-from-the-first-row/m-p/76462#M6212</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Several functionally equivalent code snippets were provided.&amp;nbsp; I doubt the performance differences between the different code snippets will be noticeable, let alone significant.&amp;nbsp; I think it is mostly a matter of style and what you prefer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lately, if I don't need to re-use the cursor, I have been using a variation of the one liner offered by &lt;A href="https://community.esri.com/migrated-users/3100" target="_blank"&gt;Xander Bakker&lt;/A&gt;‌:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcpy

fc &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'c:/data/base.gdb/features'&lt;/SPAN&gt;
values &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; next&lt;SPAN class="punctuation token"&gt;(&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; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'OID@'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'SHAPE@AREA'&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;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:57:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-the-value-of-a-field-from-the-first-row/m-p/76462#M6212</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-10T22:57:35Z</dc:date>
    </item>
  </channel>
</rss>

