This question already has an answer here:
When creating a Layer in arcpy, the syntax uses a string to denote the layer name, as shown in the Make Feature Layer sample script:
import arcpy arcpy.env.workspace = "C:\Program Files (x86)\ArcGIS\Desktop10.2\TemplateData\TemplateData.gdb" arcpy.MakeFeatureLayer_management("city", "citiesLyr") print(type("citiesLyr")) # => string
As far as Python is concerned, "citiesLyr" is just a string (right?). Can I instead define the feature layer as a variable?
This is an attempt to simplify a more complicated scenario. I'm trying to use the feature layer in a script which involves multiprocessing, loops and functions, and I'm finding that the reference to the layer is being lost, and all I'm left with is a string called "citiesLyr". How can I keep the reference to the feature layer throughout my script?
The example below doesn't do anything - the point is to test how to gain access to the feature layer from within the function, which has been called within the multiprocessing environment:
import multiprocessing, arcpy def doCity(lyr): #How to get access to the cities layer from this function? print(lyr) desc = arcpy.Describe(lyr) # <= this fails because the layer is just a string print(desc.SpatialReference) if __name__ == '__main__': #Create a feature layer from the cities arcpy.MakeFeatureLayer_management("C:\Program Files (x86)\ArcGIS\Desktop10.2\TemplateData\TemplateData.gdb\city", "citiesLyr") #Create a list, so we can use the multiprocessing function citiesList =  for i in range(0,5): citiesList.append("citiesLyr") # Create a pool class and run the jobs pool = multiprocessing.Pool() pool.map(doCity, citiesList) # Synchronize the main process with the job processes to ensure proper cleanup. pool.close() pool.join()
(The cities list itself is also pointless - it's only there to use multiprocessing)