Sort_management in for loop

875
3
Jump to solution
03-12-2013 06:25 AM
AdityarajChavada
New Contributor III
Hello, I like to convert tables (100+) living in access database to a geodatabase table, sorting them and deleting unnecessary fields in each table at the same time. I figured I use the Sort_management method to convert and sort the tables followed by DeleteFieldd_management method to delete the fields. Here is the code that I have written,

import arcpy  from arcpy import env  env.workspace = "E:\Database Project\ACS Estimate 2011\ACS 2011 Tables.mdb"  tableList = arcpy.ListTables()  for table in tableList:      out_dataset = "E:\Database Project\ACS Estimate 2011\Data\To Database\Seq Tables.gdb"      #Process: Sort     arcpy.Sort_management(table, out_dataset, "GEOID ASCENDING", "UR")      #Process: Delete Field     arcpy.DeleteField_management(out_dataset, "FILEID;FILETYPE;STUSAB;CHARITER")


I am getting the following error message,
[ATTACH=CONFIG]22543[/ATTACH]
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RaphaelR
Occasional Contributor II
your out_dataset points to a gdb, not a feature classs or table as required.

you could try this, which should give each table in the output database the same name it had in the input database.

out_dataset = r"E:\Database Project\ACS Estimate 2011\Data\To Database\Seq Tables.gdb" + "\\" + table


edit: forgot to make it a raw string.

View solution in original post

0 Kudos
3 Replies
RaphaelR
Occasional Contributor II
the link to your attachment doesn´t work for me:
"Invalid Attachment specified. If you followed a valid link, please notify the administrator"
0 Kudos
AdityarajChavada
New Contributor III
I am not sure what happened but I re-added the error message. Let me know if it works now. Thank you.
0 Kudos
RaphaelR
Occasional Contributor II
your out_dataset points to a gdb, not a feature classs or table as required.

you could try this, which should give each table in the output database the same name it had in the input database.

out_dataset = r"E:\Database Project\ACS Estimate 2011\Data\To Database\Seq Tables.gdb" + "\\" + table


edit: forgot to make it a raw string.
0 Kudos