|
At 9.3, the geoprocessor is a little bit more Pythonic than at 9.2 concerning the GP "List" methods. ListFields, ListIndexes, ListDatasets, ListFeatureClasses, etc, all return real python lists now, but before they'd return an object that you had to enumerate through. The new pythonic style is much cleaner. gp.ListFeatureClasses(r"C:\temp) ----> [u'States.shp', u'Rivers.shp', u'crackHouses.shp'] This output list is a "normal" python list with methods like append, pop, count, remove, insert, reverse, sort, etc... Lists are useful if you need to queue up jobs, or move through items... You can also make new lists based on conditions of your original list with a construct called a "list comprehension" which is to say something like: newList = [x for x in originalList if x.endswith(".shp)] This list cmp above would return newList as a subset of the orginal but only containing shp files. You could do similiar for a list of attributes if you wanted to scrape the OID for a given qualifying data, etc... Try out the code below, but remember to change the workspace!
import arcgisscripting gp = arcgisscripting.create(9.3) gp.workspace = r"C:\temp" fcList = gp.listfeatureclasses() print fcList for fc in fcList: dsc = gp.describe(fc) print fc + ": "+ dsc.Shapetype fields = gp.listfields(fc) for field in fields: print "\t\t" + field.Name + "\t\t" + field.Type + "\t\t" + str(field.Length) print "\t\t" + "-" * 50 |