6

I'm pretty new in python, and I'm trying to iterate through a list of feature classes, and perform a buffer on each feature class. So I've done this:

import arcpy  
from arcpy import env  
env.workspace = "C:/EsriPress/Python/Data/Midterm/Oil_project.gdb"  
env.overwriteOutput = True  
fclist = arcpy.ListFeatureClasses("", "Polyline", "Well_Data")  

for fc in fclist  
buffer = arcpy.Buffer_analysis(fc, fcname_buffer, "75 FEET")

However, I want each output file name to be the original feature class name with _buffer at the end. For example, the name of the first feature class in the list is Well_A_BB05.shp. I want the output to be "Well_A_BB05_buffer". I can't get this to work.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Andy Fisher
  • 339
  • 2
  • 8

1 Answers1

8

In the arcpy.Buffer_analysis() set your output to be '{}_buffer'.format(fc) which will add your feature class name from fc in front of the _buffer text e.g. if your feature class is called "Line3" the output buffer feature class would be called "Line3_buffer"

import arcpy  
from arcpy import env  
env.workspace = "C:/EsriPress/Python/Data/Midterm/Oil_project.gdb"  
env.overwriteOutput = True  

fclist = arcpy.ListFeatureClasses("", "Polyline", "Well_Data")  

for fc in fclist: 
    arcpy.Buffer_analysis(fc, '{}_buffer'.format(fc), "75 FEET")
Midavalo
  • 29,696
  • 10
  • 48
  • 104