I have 150 shapefiles in folder in "D:\ss3\polygons". I want to save each polygon as .layer file with the polygon name in "D:\ss3\layers"
However, Python displays: "Parsing error SyntaxError: invalid syntax (line 3). I am really confused.
Does anyone have any idea how to fix the SyntaxError and if my code is correct?
import arcpy
#folder locations
in_polygon_folder = "D:\ss3\polygons"
out_layer_folder = "D:\ss3\layers"
arcpy.env.workspace = in_polygon_folder
in_polygon_folder = arcpy.ListFeatureClasses("*", "ALL")
for polygon in in_polygon_folder:
... polygon_name = polygon[:-4]
... polygon_name = in_polygon_folder+"\\"polygon_name+"plg.shp"
... out_layer_folder = out_layer_folder+"\\"+polygon_name+"layer.lyr"
... arcpy.MakeFeatureLayer_management("buf_layer", out_layer_folder, "256", "NONE", "NOMAINTAIN_EXTENT")
Againg I apologize for my mistake. My code (I include) works well, however, without the for loop I have write 150 lines to save each polygon shp as .lyr file. This my code:
import arcpy
from arcpy import env
env.workspace = r"D:\ss3\polygons"
buf= r"D:\ss3\polygons\00.shp"
ou2= r"D:\ss3\layers\002.lyr"
arcpy.MakeFeatureLayer_management(buf, 'buf_layer')
arcpy.SaveToLayerFile_management('buf_layer', ou2, "ABSOLUTE")
What I am trying to do is to include my code into a for loop.