I would like a script that will be executed in ArcGIS that only deletes fields within an attribute table that are specified by the user. As I understand it, this can be done in Modelbuilder but was curious if I script would do the same.

When I say specified by the user, I wish the script tool to give the user all the fields within the attribute table and allow them to select which ones they wish to delete.

1 Answer 1


Why not just use the Delete Field tool within the Fields toolbox?

ArcToolbox --> Data Management Tools --> Fields --> Delete Field

Choose your input table/feature class, and select the fields you want to remove.

If you want to script it out to delete certain fields every time, it'd be pretty easy.

arcpy.DeleteField_management(in_table, drop_field)

Example from the documentation:

import arcpy
arcpy.DeleteField_management("C:/output/roads.shp", ["STREET_NAM", "LABEL", "CLASS"])
  • The only part of the question this doesn't address is giving the user all the fields within the attribute table (though I wonder why this is a requirement).
    – juturna
    Apr 14, 2015 at 16:51
  • 1
    It does if you use the actual ESRI tool. When you select the input table/feature class, it lists all the fields. However, you're correct on the scripting part, but I also don't see why that'd be necessary. They might as well just use the built-in tool.
    – ianbroad
    Apr 14, 2015 at 16:53
  • Listing all the fields in attribute (and not using the built in feature) is something that is required (ie: I would like to do it). If it's not possible, I can keep it as a Modelbuilder.
    – user48149
    Apr 14, 2015 at 17:06
  • I'm not really sure what you want to do? Do you want this as like a command line tool that lists all the fields, and the user chooses which ones to remove?
    – ianbroad
    Apr 14, 2015 at 17:11
  • Precisely. I would like it to be like a command tool, list all the fields and have the user select which one they want to drop.
    – user48149
    Apr 14, 2015 at 17:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.