christi_nelson

How to populate a list using multiple fields from a table?

Discussion created by christi_nelson on Feb 23, 2013
Hi all,

Below is a script that creates and empty list, loops thru a parcels feature class, gets the value for each record in the 'APN_NU_1' field and populates the list with the values.  This runs perfectly.  How do I write this script to populate the list with multiple fields and their values, say 'APN_NU_1', 'ADDR_B', and 'CITY'?

import modules and define workspace
import arcpy
import os
import traceback


workspace = arcpy.env.workspace = "E:/dev/Christi/PSL/" 

arcpy.env.overwriteOutput = True

#Define map document
mxDoc = arcpy.mapping.MapDocument("CURRENT")


#List the first dataframe (named Layers) in the map document
df = arcpy.mapping.ListDataFrames(mxDoc, "Layers") [0]


#List first map layer (which is the parcels layer) in dataframe
parcelLayer = arcpy.mapping.ListLayers(mxDoc,"",df) [0]


#Select parcel layer by attribute and clear any previously selected features
#Set up a Search Cursor to go thru the attribute table and get row values 
#Set up variable, then read the row values for 'APN_NU_1' field and populate the list

arcpy.SelectLayerByAttribute_management(parcelLayer,"CLEAR_SELECTION")

rows = arcpy.SearchCursor(parcelLayer)
stringList = []
for row in rows:
        stringList.append(row.getValue('APN_NU_1'))

Outcomes