rgthurau

Syntax help: defining a function in python

Discussion created by rgthurau on Oct 13, 2011
Latest reply on Nov 8, 2011 by rgthurau
Hi,
Trying to write a code based on what I've learned in another thread

What I would like to do: Loop through each feature in a featureclass, select each feature, buffer, export as an individual featureclass.

What I am trying to do with this script: Select features "Grid_Num" = 7 and 22, buffer them, and export them as individual feature classes.

Here's my code:
import arcpy
##from arcpy.sa import *
from arcpy import env
##arcpy.CheckOutExtension("Spatial")
workspace = arcpy.env.workspace = "X:\\Grid\\Grid_Working.gdb\\All_Tiles\\"
##arcpy.env.overwrightOutput = True
GDB = "X:\\Grid\\Grid_Working.gdb\\All_Tiles\\"
FC = "X:\\Grid\\Grid_Working.gdb\\All_Tiles\\Grid_w_rShad"
fieldName = "Grid_Num"
buf = '200 feet'

def selectBufExport(GDB, FC, fieldName, fieldVal, buf):
    selection = arcpy.selectByAttributes(GDB +'\\'+ FC, '%s = %s' % (fieldName, fieldVal))
    bufferedSelection = arcpy.Buffer(selection, buf)
    arcpy.Export(bufferedSelection, GDB + '\\' + '%s_%s_tile' % (fieldName, fieldVal))

for (fieldVal, buf) in [(7, buf), (22, buf)]:
    selectBufExport(GDB, FC, fieldName, fieldVal, buf)


Error message:    
selection = arcpy.selectByAttributes(GDB +'\\'+ FC, 'fieldName = 7')
AttributeError: 'module' object has no attribute 'selectByAttributes'


Stacy R, I tried writing this from your example cited above, but I'm not savvy enough!

Looking for help solving this issue, or advice on how to improve, and suggestions for learning more in general. Much appreciated.

Rich

Outcomes