我正在尝试使用Python中的while循环从属性表中打印条目,特别是高中设施名称。我可以使用for循环打印出高中名字,但是我错过了使用while循环的东西。
#code using for loop:
import arcpy
try:
work = raw_input("Enter the full workspace path: ")
arcpy.env.workspace = work
fcs = "Schools.shp"
whereClause = "\"FACILITY\" = 'HIGH SCHOOL'"
searchCurs = arcpy.SearchCursor(fcs, whereClause, "", "", "")
row = searchCurs.next()
row.Name
for row in searchCurs:
print row.Name
except Exception as e:
print "Error: " + str(e)
print arcpy.GetMessages()
arcpy.AddError(e)
#code using while loop:
import arcpy
try:
work = raw_input("Enter the full workspace path: ")
arcpy.env.workspace = work
fcs = "Schools.shp"
field = "FACILITY"
whereClause = "\"FACILITY\" = 'HIGH SCHOOL'"
searchCurs = arcpy.SearchCursor(fcs, whereClause, "", "", "")
row = searchCurs.next()
while row:
print(row.getValue(field))
row = searchCurs.next
except Exception as e:
print "Error: " + str(e)
print arcpy.GetMessages()
arcpy.AddError(e)
for
循环脚本有效。如何使while
循环起作用?
答案 0 :(得分:1)
我明白了。我忘了()在row.next之后。