BrokenLegMike

arcpy.DeleteFeatures_management isn't deleting Feature Layers

Discussion created by BrokenLegMike on Aug 31, 2011
Latest reply on Aug 31, 2011 by BrokenLegMike
Hey everyone,

I am trying to test to delete a feature layer in a python script, but it doesn't seem to delete it. I created a feature layer using MakeFeatureLayer_management for a couple feature classes and did a test to delete them immediately afterwards because my original script kept errorring out saying that the feature already existed.

In my following script, I created 2 "for" loops and then created a feature layer and deleted afterwards. I tested this by setting a print statement to print out the feature layer immediately after I deleted it. My expectation was to have nothing returned on the print statement after I deleted it, but it actually returns the feature layer which is why my original script gets hung up. Can anyone suggest why the feature layer isn't getting deleted?


My script is as follows:

import arcpy

from arcpy import env

arcpy.workspace = r"Z:\ESRI\Figure_Sourcing\Figures\Geodatabase\D01_PDA_CR.gdb"

fcList3 = arcpy.ListFeatureClasses("*", "Polygon")
fcList4 = arcpy.ListFeatureClasses("*", "Point")

for fc3 in fcList3:
        for fc4 in fcList4:
                if fc3 == "Parcels" and fc4 == "Points":
                        print fc3
                        print fc4
                        test1 = arcpy.MakeFeatureLayer_management(fc3,"polygon2")
                        test2 = arcpy.MakeFeatureLayer_management(fc4,"point2")
                        arcpy.DeleteFeatures_management("polygon2")
                        arcpy.DeleteFeatures_management("point2")
                        print test1
                        print test2

Outcomes