函数正好需要 3 个参数(给定 1 个)?帮助格式化打印语句
Function takes exactly 3 arguments (1 given)? Help formatting print statement
这是我的问题:
创建一个名为 "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所高中)同时包括必要的论据。
您需要显式传递参数。
count = numSchools(work, shapefile, sTyp)
print("There are a total of: ", count)
这是我的问题:
创建一个名为 "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所高中)同时包括必要的论据。
您需要显式传递参数。
count = numSchools(work, shapefile, sTyp)
print("There are a total of: ", count)