TransWikia.com

Using arcpy.da.SearchCursor to sort field in attribute table by ascending order

Geographic Information Systems Asked by fortheloveofgis on February 14, 2021

I am using ArcMap 10.6 with Python 2.7.14 with ArcPy.

I want to sort a field named Seq_ID in my attribute table by ascending order using ArcPy.

I believe I have to use arcpy.da.SearchCursor.

Here is my code snippet:

for row in arcpy.da.SearchCursor(points, fields, sql_clause=(None,'ORDER BY Seq_ID ASC'):
     arcpy.AddMessage("")
else:
    arcpy.AddMessage("")

However, after using this snippet above, my table is not sorted.

One Answer

You are using a search cursor to READ your dataset and applying a sort whilst reading it, you are not editing it!

If you want to permanently sort rows in a table you need to use the SORT tool, this will create a new dataset sorted.

Answered by Hornbydd on February 14, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP