arcgis - Adding Values to an Array and getting distinct values using Python -


i have python code below loop through table , print out values within particular column. not shown form in user selects feature layer. once feature layer selected second dropdown populated column headings feature , user chooses column want focus on. within python script, print out each value within column. want store each value in list or array , distinct values. how can in python?

also there more efficient way loop through table go row row? slow reason.

many thanks

# import system modules import sys, string, os, arcgisscripting  # create 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 feature layer user wants query against atts = sys.argv[2]          #this column name user selected  #lets loop through rows values particular column            fc = input_dataset  gp.addmessage(atts)  rows = gp.searchcursor(fc) row = rows.next() newlist = []  row in gp.searchcursor(fc):     ##grab field values     fcvalue = fields.getvalue(atts)     newlist.add(fcvalue) 

you can store distinct values in set:

>>> = [ 1, 2, 3, 1, 5, 3, 2, 1, 5, 4 ] >>> b = set( ) >>> b {1, 2, 3, 4, 5} >>> b.add( 5 ) >>> b {1, 2, 3, 4, 5} >>> b.add( 6 ) >>> b {1, 2, 3, 4, 5, 6} 

also can make loop more pythonic, although i'm not sure why loop on row begin (given not using it):

for row in gp.searchcursor( fc ):     ##grab field values     fcvalue = fields.getvalue(atts)     gp.addmessage(fcvalue) 

and btw, """ text """ not comment. python has single line comments starting #.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -