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'm trying to sort a table based on three fields with ArcPy (which should be only one line of code), and I had a "tool is not license" error. I just saw that sorting with multiple fields as parameters is an ArcInfo feature only. I have ArcView (soon ArcEditor).

Any ideas how I could code this to bypass that limitation with ArcPy?

share|improve this question
up vote 5 down vote accepted

You could create a new empty table and use cursors to sort your data and insert the rows into the new table (this code has not been tested):

import acrpy,os

inTable = r'c:\workspace\path\in_table.dbf'
outPath = r'c:\workspace\path'
sortedTableName = r'sorted_table.dbf'
arcpy.env.workspace = outPath
arcpy.overwriteOutput = True

#--check if output table exists, if not, create it
if not os.exists(os.path.join(outPath,sortedTableName)):

    #--make a list of all fields in input table
    flist = arcpy.ListFields(inTable)

    #--add fields to output table
    for f in flist:

#--if the table does exist, delete all rows so we can start fresh
        #--no rows to delete

#--create an insert cursor that will append data to output table
irows= arcpy.InsertCursor(os.path.join(outPath,sortedTableName))

#--create a search cursor to sort and then read data from input table
rows = arcpy.SearchCursor(inTable,'#','#','#','SORT_FIELD1 A;
                            SORT_FIELD2 D;
                            SORT_FIELD3 A')
for row in rows:
    #--create a new row object in the output table
    newrow = irows.newRow()
    #--populate each field
    for f in flist:
    #--insert new row

del irows,rows
share|improve this answer
Didn't thought of that one! Thanks! – fgcartographix Apr 3 '12 at 16:51
@fgcartographix, let me know if this works, if it does I'd appreciate it if you'd click on "accept answer"! :O) – Jason Apr 3 '12 at 17:22
Thats a very clever workaround. Great idea. – RyanDalton Apr 3 '12 at 17:30
Of course... already clicked. In theory, it should work well... – fgcartographix Apr 3 '12 at 17:44
@fgcartographix, I updated the code to handle the case where the table already exists and has rows in it (e.g. the script ran, and inserted some rows, but then bombed). – Jason Apr 3 '12 at 17:51

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.