filipkral

ArcGIS 10.3.x Python 3.4 cannot delete layer

Discussion created by filipkral on Nov 13, 2015
Latest reply on Aug 5, 2016 by filipkral

Hello,

I need to create a layer, then delete it and then create a layer of the same name again. The script below works as expected in Python 2.7 32 bit, but fails in Python 3.4 64 bit in ArcGIS 10.3.1.

Can anyone explain why?

 

import arcpy

in_fc=r'C:\dump.gdb\zn3_0'
w = "STATION=3001"
lrname = 'lr1'

# create a layer
lr = arcpy.management.MakeFeatureLayer(in_fc, lrname, w).getOutput(0)
print(arcpy.Exists(lrname)) # True

# delete the layer
arcpy.management.Delete(lr)
arcpy.management.Delete(lrname)
del lr
print(arcpy.Exists(lrname)) # should be False but returns True in Python 3.4!

# create the layer again fails in Python 3.4
lr = arcpy.management.MakeFeatureLayer(in_fc, lrname, w).getOutput(0)
# ERROR 000725: Output Layer: Dataset lr1 already exists.

# and indeed the layer still exists after the error
print(arcpy.Exists(lrname)) # True
arcpy.management.GetCount(lrname).getOutput(0) # 1

Filip.

Outcomes