Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to return the first record of a feature class as a list. Is this possible? I can't seem to figure it out using row.getValue() as it does not allow me to put a wildcard in there.

share|improve this question
Are you looking to return a list of all the values for each of the fields in 1 list? – dklassen Apr 9 '14 at 17:52
What version of ArcGIS are you using, 10.1? – the_skua Apr 9 '14 at 17:55
ArcGIS version 10.0 – Rusty Shackleford Apr 9 '14 at 17:56
I just need the first row as a list, so something like [0,"NJ","123 street"] – Rusty Shackleford Apr 9 '14 at 17:57
@wannabe_n00b please edit your question to include this information, as well as what you've tried. This site works best when questions include all necessary details rather than having to fish them out of the comments. – blah238 Apr 9 '14 at 19:09

Give this a try:

import arcpy

fields = [ for f in arcpy.ListFields(ds)]
cur = arcpy.SearchCursor(ds)
outlist = []
for row in cur:
    for field in fields:
share|improve this answer
I basically had this already, I was hoping I didn't need this many lines. BTW, you don't need to do list comprehension in your 4th line if you just do getValue( – Rusty Shackleford Apr 9 '14 at 18:12
If you already have this - I am not sure what you are looking for then? This works! – dklassen Apr 9 '14 at 18:14
@ian you could do: fields = arcpy.ListFields(ds) then in the cursor simply do, but I prefer my way in this case! – dklassen Apr 9 '14 at 18:45

Since you asked for a 1-liner:

firstRow = next(([row.getValue(field) for field in ( for f in arcpy.ListFields(ds))] for row in arcpy.SearchCursor(ds)), None)

This uses a generator expression and the next() built-in function to short-circuit the evaluation of the generator such that only the first row is fetched. The None argument avoids a StopIteration exception from being raised if there are no rows in the dataset.

This is a lot easier in 10.1, BTW (arcpy.da cursors return tuples).

share|improve this answer
This is what makes Python so cool - so many different approaches to do the same thing! And it gets better all the time. – dklassen Apr 9 '14 at 18:48
I was hoping arcpy had a built in that retrieved all attributes but this will have to suffice. – Rusty Shackleford Apr 9 '14 at 20:04
As I mentioned, at 10.1 and up it does with arcpy.da cursors. – blah238 Apr 9 '14 at 20:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.