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.
Since you asked for a 1-liner:
firstRow = next(([row.getValue(field) for field in (f.name 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).