Well, there is no PrecinctNa in row2 becauserows2 is a cursor, and contains the table, not an individual row.You don't really want to use cursors to do thisand you need layers to drive PointDistanceimport arcpy
from arcpy import env
env.workspace = "C:\work"
env.overwriteOutput = True
# Local variables:
Voters = "Voters.shp" # these are the voters, point file
PollingSite = "Polling.shp" # this is the point file of the voter sites
distance = "distance.DBF" # this will be the output of the distance table
rows = arcpy.SearchCursor(PollingSite)
## build a list of sites with a search cursor
sitesList = []
for row in rows: #rows is the PollingSite shapefile
p_precinct = row.Pre #this is the precinct column for PollingSite
if p_precinct not in sitesList:
sitesList.append(p_precinct)
for site in sitesList:
Votewhere = '"PrecinctNa" = %s' % (site)
Sitewhere = '"Pre" = %s' % (site)
## don't depend on env.overwriteOutput
if arcpy.Exists("PollPlace_Lyr"):
arcpy.Delete_management("PollPlace_Lyr")
if arcpy.Exists("Voter_Lyr"):
arcpy.Delete_management("Voter_Lyr")
if arcpy.Exists("Point_Tbl"):
arcpy.Delete_management("Point_Tbl")
arcpy.MakeFeatureLayer_management(Voters, "Voter_Lyr", Votewhere)
arcpy.MakeFeatureLayer_management(
PollingSite, "PollPlace_Lyr", Sitewhere)
arcpy.PointDistance_analysis("Voter_Lyr",
"PollPlace_Lyr",
"Point_Tbl")
arcpy.Append_management("Point_Tbl", distance)
## this assumes distance.DBF exists and has the
## correct schema
untested: for illustration only: no warranties expressed or implied