2
我試圖從屬性表中使用Python中的while循環打印條目,特別是高中的設施名稱。我可以使用for循環打印出高中名稱,但我錯過了while循環的一些內容。Python 2.7:ArcPy遊標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
循環正常工作?