I am rewriting a script for Python 3.6 and ArcGIS Pro compatibility and it seems like user defined functions will be necessary to clean it up. I am fairly new. I separated the code block into two functions and I would like to call the first function in the beginning of the second function. I'd also like to call the first function near the bottom but I'm getting a NameError. Here is the code block that I am working on.
def select_address(): for lyr in m.listLayers(): if lyr.name == "LOCATION.addresspoint": CoaAddresses = lyr selection = arcpy.SelectLayerByAttribute_management(CoaAddresses,"NEW_SELECTION", expression) return(selection) def found_address(): select_address() print(selection) for row in arcpy.SearchCursor(selection): #retrieve address of selected feature selectedAddress = row.FULL_STREET_NAME #this variable used later for legend return(selectedAddress) select_address() results = arcpy.GetCount_management(selection) #return number of features selected
the error I get:
results = arcpy.GetCount_management(selection) #return number of features selected
NameError: name 'selection' is not defined
selection be defined in the
def select_address(): portion of the script?