Hi All,
I am trying to use a for loop in arcpy, but am unsure of how to name the output using the variables from the list. I have attached a snippet of the code. Please let me know of any ideas. The list are all variables that are set to shapefiles. Please let me know if you have any ideas. Thanks!
#for loop
x=[ECO, HPA, POT, NAV, OPA]
for i in x:
arcpy.Clip_analysis(i, "Pipeline_Buffer", i + "Areas")
do you variables have a path associated with them?
in otherwords is ECO actually c:/path/eco.shp
because if you want to append "area" to that name, then you are going to have to parse out the *.shp part and add it back
ie temporarily parse off the shp part and add it back on. This is the most explanatory form
>>> ECO = "c:/mypath/eco.shp"
>>> ENEW = ECO[:-4]+"AREA"+".shp"
>>> ENEW
'c:/mypath/ecoAREA.shp'
Or (more slicing and dicing...)
>>> p = "c:/myPath/myShape.shp" >>> p 'c:/myPath/myShape.shp' >>> pNew = "{}{}{}".format(p.split(".")[0], "Area.", p.split(".")[1]) >>> pNew 'c:/myPath/myShapeArea.shp' >>>
Yes, but fancy formatting is not intro level as is slicing. But it is elegant ...
>>> ECO = "c:\mypath\eco.shp" >>> "{}{}{}".format(ECO[:-4],"Area",ECO[-4:]) 'c:\\mypath\\ecoArea.shp
Fancy, fancy formatting for the explorer
and ensures the correct path format