Python: DeleteField Management_for loop

4013
4
Jump to solution
02-02-2015 08:24 AM
LarryAdgate
Occasional Contributor

If someone could help me with this, I would forever be greatful. My preference is not to repeat DeleteField_management three times for the three diffrent feature classes, but to use a for loop and loop through all the feature classes except my creation will not work. Please help

Thanks, Larry 

# Import arcpy module
import arcpy

# Local variables:
Arden = "C:\\Projects\\TestProject.gdb\\Project\\Arden"
Baypoint = "C:\\Projects\\TestProject.gdb\\Project\\Baypoint"
Clearlake = "C:\\Projects\\TestProject.gdb\\Project\\Clearlake"

mylist = Arden, Baypoint, Clearlake

for delete in mylist:
     arcpy.DeleteField_management(mylist, "Pump;Well;Tank")

     print "Finished the Delete Function"   

0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

It is helpful to post specific error messages, if any, as well.

Try changing your second to last line to:

arcpy.DeleteField_management(delete, ["Pump", "Well", "Tank"])

View solution in original post

4 Replies
JoshuaBixby
MVP Esteemed Contributor

It is helpful to post specific error messages, if any, as well.

Try changing your second to last line to:

arcpy.DeleteField_management(delete, ["Pump", "Well", "Tank"])

LarryAdgate
Occasional Contributor

Thanks Joshua, 

Larry

0 Kudos
EarlSarow
New Contributor III

I believe you're passing the wrong variable to DeleteField_management.  You want to pass the current feature class in your loop ("delete"), not the list of feature classes you're looping over. 

LarryAdgate
Occasional Contributor

Thanks Earl, That was great information and it was enough to get me going again.

Larry

0 Kudos