5

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.

7

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")
  • 2
    @AndyFisher Please consider accepting this answer by selecting the green check mark next to the answer. This question can then be considered resolved. – Aaron Mar 13 '16 at 16:45

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.