How to get the value of a field from the first row without looping?

16882
10
02-26-2015 10:45 AM
SaidAkif
New Contributor III


Hi all,

I am wondering how to get the value a field frorm the first row without looping through all the rows?

Thanks

0 Kudos
10 Replies
JoshuaBixby
MVP Esteemed Contributor

Several functionally equivalent code snippets were provided.  I doubt the performance differences between the different code snippets will be noticeable, let alone significant.  I think it is mostly a matter of style and what you prefer.

Lately, if I don't need to re-use the cursor, I have been using a variation of the one liner offered by Xander Bakker‌:

import arcpy

fc = 'c:/data/base.gdb/features'
values = next(arcpy.da.SearchCursor(fc, ['OID@', 'SHAPE@AREA']))