I ran a script for location allocation on ArcPy, which worked.

After running it, I used the Save to Layer File to save the result.

Now that I have the result saved (and can even open on ArcMap), I want to reload that file into a Python script to do some work on it.

How do I load/read/open the layer file into Python again? Basically the reverse process of Save to Layer File, where you input a file path and it outputs a object that is the results layer.


In ArcGIS Desktop 10.x you use arcpy.mapping.Layer

lyr = arcpy.mapping.Layer(r"path\to\file.lyr")
print lyr.name

In ArcGIS Pro you use arcpy.mp.LayerFile:

lyrFile = arcpy.mp.LayerFile(r"path\to\file.lyrx")
for lyr in lyrFile.listLayers():

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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