Skip to content

Instantly share code, notes, and snippets.

@tyler-austin
Created May 30, 2017 21:37
Show Gist options
  • Save tyler-austin/679f08f8afedce7da7a649c208eeb1ab to your computer and use it in GitHub Desktop.
Save tyler-austin/679f08f8afedce7da7a649c208eeb1ab to your computer and use it in GitHub Desktop.
arcpy print first x rows
import arcpy
import os
def _print_top_rows(vector_data, num_rows=10):
field_names = [f.name for f in arcpy.ListFields(vector_data)]
print field_names
i_row = 0
with arcpy.da.SearchCursor(vector_data, ['*']) as cursor:
for row in cursor:
if i_row < num_rows:
print row
i_row += 1
del cursor
vector_data = os.path.join(r"/path/to/feature/class")
first_10_rows = _print_top_rows(vector_data)
num_rows = 15
first_15_rows = _print_top_rows(vector_data, num_rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment