2015-07-19 133 views
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循环正常工作?

回答

1

我想通了。我在row.next后忘了()。