函数正好需要3个参数(给定1个)?帮助格式化打印语句

时间:2017-01-31 00:07:50

标签: python wing-ide

以下是我的问题:

创建一个名为“numSchools”的函数,该函数计算特定类型的学校。该函数应该有三个输入参数,(1)工作空间的字符串,(2)shapefile名称的字符串,(3)设施类型的字符串(例如“HIGH SCHOOL”)和一个输出参数, (1)shapefile中该设施类型的学校数量的整数。

import arcpy

shapefile = "Schools.shp"
work = r"c:\Scripts\Lab 6 Data"
sTyp = "HIGH SCHOOL"

def numSchools(work, shapefile, sTyp):

    whereClause = "\"FACILITY\" = 'HIGH SCHOOL' " # where clause for high schools
    field = ['FACILITY']
    searchCurs = arcpy.SearchCursor(shapefile, field, whereClause)
    row = searchCurs.next()
    for row in searchCurs:
    # using getValue() to get the name of the high school
    value = row.getValue("NAME")

    high_schools = [row[0] for row in arcpy.SearchCursor(shapefile, field, whereClause)]
    count = arcpy.GetCount_management(high_schools)
    return count

numSchools(work, shapefile, sTyp)
print ("There are a total of: "),count

所以这是我的代码完美运行,但它是通过脚本完成的。我需要将它包装成python函数。 (我的弱点)。似乎我的代码的最后一行存在一些问题。 `

我不太清楚如何格式化最后一行代码来阅读 (共有29所高中),同时包括必要的论据。

1 个答案:

答案 0 :(得分:1)

您需要显式传递参数。

count = numSchools(work, shapefile, sTyp)
print("There are a total of: ", count)