I will often create many temporary layer files with MakeFeatureLayer_management. I was wondering if there was a means to list the temporary layer files I've created. I've tried setting the workspace to "in_memory" and applying ListDatasets () and ListFiles (), but since these layers don't seem to actually be stored in "in_memory", this doesn't produce my desired results. Is there another location these files are stored that I can access? it would be nice to just be able to list all my created layers and delete them without having to keep track of each, to free up locks and what have you.

2 Answers 2


This worked for me:

import arcpy

contours = r'C:\TEMP\Contours.shp'
con2 = r'C:\TEMP\Contours2.shp'
d = {'a': 1, 'b': 2}
_list = [1,2,3]
string = 'test'

lyr1 = arcpy.MakeFeatureLayer_management(contours, 'contours1').getOutput(0)
lyr2 = arcpy.MakeFeatureLayer_management(con2, 'contours2').getOutput(0)
layers = [globals()[v] for v in dir() if isinstance(globals()[v], arcpy.mapping.Layer)]

print layers

for lyr in layers:
    print lyr.dataSource

[<map layer u'contours1'>, <map layer u'contours2'>]

However, when you call the make feature layer function it is always made from an existing feature class or shapefile.

  • Nice! Can you explain what is going on in this line, for my own understanding? layers = [globals()[v] for v in dir() if isinstance(globals()[v], arcpy.mapping.Layer)] I understand this is making a list, but why globals, and what does dir() do? Dec 22, 2014 at 20:42
  • 1
    No problem, using the globals() will return a dictionary of the variable names and their respected values. The dir() returns a list of the variables. The line you are asking about is just a list comprehension that checks to see if the variable type is an arcpy.mapping.Layer, which is the data type returned from the MakeFeatureLayer() function. If a variable is of the layer type, it is added to the list.
    – crmackey
    Dec 22, 2014 at 20:45

Have you tried ListLayers()? I don't see where in-memory is specifically addressed in the Help File, but worth a shot.

  • Hmm... it requires a map doc or layer file as input. Not quite what I'm after. Dec 22, 2014 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.