Solved! Go to Solution.
Aha, that's a good point about the locks, Curtics. So it's best to delete the layer as soon as you are done doing what you needed the layer (or table view) for.
Do you copy and paste this code into the console, or run it from somewhere else? See my post below; it'll be a good thing for me to add to my python package...
Adam,
I include that cleanup def() in just about all of my .py source files to any of the Geoprocess tools I build that utilize in_memory space. But like Curtis said, it's a little off topic to this thread.
This is all great info, and I especially like the delete everything in memory function. I thought I'd throw my own two cents in also... I began to deal with deleting feature classes like this a while ago by creating my own little python module. It's super useful to have a some functions that you can call anytime from anywhere, because I need to do this "delete if exists" thing all the time (plus a lot of other stock operations that I'm tired of retyping).
Just make a folder in your python site-packages directory (something like C:\Python2x\Lib\site-packages, or, more likely, C:\Python2x\ArcGIS10.x\Lib\site-packages) called mypack, and then in that folder create a text file called __init__.py. You can define all the functions you want in there, and to access them from any console or script just say "from mymod import functionname".
For what we're talking about here, I just have this in the __init__.py file:
import arcpy
def TakeOutTrash(dataset):
if arcpy.Exists(dataset):
arcpy.management.Delete(dataset)
so in the console, making a feature layer could look like:
from mypack import TakeOutTrash
fl = "fl"
TakeOutTrash(fl) # this is important if you are iterating or running the script many times
arcpy.management.MakeFeatureLayer(r"path",fl)
##do some stuff with feature layer
TakeOutTrash(fl)
That function could be modified to accept a list of datasets too, I just haven't done that yet.