# scriptWithFunction.py (compare to scriptWithoutFunction.py)
# Purpose: Call three tools (to find avg. nearest neighbor, intersection, and get count)
#          Print the results from avg. nearest neighbor and get count using a function.
# Usage: No script arguments needed.
import arcpy
baseDir = 'C:/gispy/'
arcpy.env.workspace = baseDir +'data/ch15/tester.gdb'
outputWorkspace = baseDir + 'scratch'
arcpy.env.overwriteOutput = True


def reportResults(resultObj):
    '''Print selected result messages.'''
    resList = resultObj.getMessages().split('\n')
    arcpy.env.overwriteOutput = True
    for message in resList:
        if '...' not in message and 'Time:' not in message:
            print(message)

res = arcpy.AverageNearestNeighbor_stats('schools')
reportResults(res)  # Call the function.
outFC = outputWorkspace + '/intersectOutput.shp'
arcpy.Intersect_analysis(['schools', 'workzones'], outFC)

res = arcpy.GetCount_management(outFC)
reportResults(res)  # Call the function.
