我有下面的python代碼,它將通過表循環並打印出特定列中的值。未示出的是用戶選擇特徵層的形式。選擇要素圖層後,會爲該要素填充第二個下拉列表的所有列標題,然後用戶選擇要關注的列。現在在Python腳本中,我只是打印出該列中的每個值。但我想要將每個值存儲在List或Array中並獲取Distinct值。我怎樣才能在Python中做到這一點?將值添加到數組並使用Python獲取不同的值
還有一種更有效的方式來遍歷表,而不是逐行?出於某種原因,這非常緩慢。
千恩萬謝
# Import system modules
import sys, string, os, arcgisscripting
# Create the Geoprocessor object
gp = arcgisscripting.create(9.3)
gp.AddToolbox("E:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")
# Declare our user input args
input_dataset = sys.argv[1] #This is the Feature Layer the User wants to Query against
Atts = sys.argv[2] #This is the Column Name The User Selected
#Lets Loop through the rows to get values from a particular column
fc = input_dataset
gp.AddMessage(Atts)
rows = gp.searchcursor(fc)
row = rows.next()
NewList = []
for row in gp.SearchCursor(fc):
##grab field values
fcValue = fields.getvalue(Atts)
NewList.add(fcValue)
埃。使用'set',你會一切設置。 +1。 – 2010-10-07 16:54:40
嗨戳,我改變了我的代碼,以反映你的調整,我得到一個錯誤。你看到上面有什麼問題嗎?我現在把set()留出來,直到我得到循環工作 – Josh 2010-10-07 18:31:59
我想知道的是(a)爲什麼你迭代'row',(b)'fields'是什麼(因爲你沒有定義它所示的代碼,但我猜想它來自其他地方)和(三)你可能會遇到問題,因爲你調用兩次'searchcursor';這可能會發生衝突,所以最好先刪除第一個電話。 – poke 2010-10-07 18:48:42