I am writing a script that cycles through several different point shapefiles, finds how many lie within a given area and the writes the outcome to a table in an Access database. I've used an search cursor to look up the point file names, which is then saved to a variable. I'd then like to use this variable to specify which field to update in another table. Here is my code:
selection = 1
while selection < 3:
rows = arcpy.SearchCursor("C:\\MyDB.mdb\\Source_Class_combinations") #opens search cursor on the info table
for row in rows:
if row.Order == selection:
destfield = row.DestField # extracts the name of the destination field
del row
del rows
print "Defining variables..."
ptfile = str(destfield)+"_lyr"
rowtoud = "row."+str(destfield) #create the variable with the field to update
# Process: Select Layer By Location
print "select by location"
arcpy.SelectLayerByLocation_management(ptfile, "INTERSECT", neighfile, "", "NEW_SELECTION")
count = int(arcpy.GetCount_management(ptfile).getOutput(0))
print "count = " + str(count)
#Update the number of points selected in the neighbourhoods table
print "updating count..."
rows = arcpy.UpdateCursor("C:\\MyDB.mdb\\neighbourhoods")
for row in rows:
if row.StudyID == str(neigh):
rowtoud = count
rows.updateRow(row)
del rows
del row
selection +=1
The selection all seems to work fine, but the table is not updated and no error message is returned. Can I use a variable like this?
I'm using ArcGIS 10, python 2.6, and Access 2007
Thanks, Flo
Best Answer
Try using the
setValue(fieldName, object)
method with your field name variable.