I have looked at other the scripts to delete feature classes in Geodatabases but all I can do is remove the feature classes from the Contents window but they are still in the Geodatabase in Catalog. I'm not sure that I am using the correct function Delete_management
import arcpy
arcpy.env.workspace = r"C:\Data\Temp.gdb"
fc_Delete = ["fcOut1a","fc_Out2a","fc_Out3a"]
for fc in fc_Delete:
if arcpy.Exists(fc):
arcpy.Delete_management(fc,"")
Solved! Go to Solution.
This is an ArcPy question, so I am sharing with Python. Questions here are more for ArcGIS API for Python.
Personally, I never rely on the workspace to assume path names because doing so inevitably causes issues like this one. If you are running this code in the interactive Python window, then what you are removing isn't the feature class but the layer that has the same name as the feature class. Even though you set the workspace, the Delete tool gives preference to layers before data sets. If you want to delete the feature class, pass the full path of the FC to the tool.
And that worked too.Thanks
This is an ArcPy question, so I am sharing with Python. Questions here are more for ArcGIS API for Python.
Personally, I never rely on the workspace to assume path names because doing so inevitably causes issues like this one. If you are running this code in the interactive Python window, then what you are removing isn't the feature class but the layer that has the same name as the feature class. Even though you set the workspace, the Delete tool gives preference to layers before data sets. If you want to delete the feature class, pass the full path of the FC to the tool.
I added the full path and that worked, Thanks
You could reassign your workspace to a new variable and do something like
import arcpy, os
arcpy.env.workspace = r"C:\Data\Temp.gdb"
cws = arcpy.env.workspace
fc_Delete = ["fcOut1a","fc_Out2a","fc_Out3a"]
for fc in fc_Delete:
fc_path = os.path.join(cws, fc)
if arcpy.Exists(fc_path):
arcpy.Delete_management(fc_path)
And that worked too.Thanks