I am working with ArcMap 10.2. In the following code, I have a function, build_dictionary, that builds a dictionary that will be used to populate a field within another layer. With the second function, update_points, I am trying to use an UpdateCursor to iterate through each feature and if that feautre's OBJECTID is a key within the dictionary, populate a field called "RoutingStreetExtKey" with that key's value.
I have verified that the build_dictionary function works properly with an "AddMessage" (and therefore omitted the code). I return the dictionary in order to use it with the next function.
The problem occurs with the update_points function. As the script runs, I can see it iterate through the point layer, however it only updates the last feature. All other features have nothing written to the "RoutingStreetExtKey" field except the very last point feature. The last feauture is populated with the correct value.
I am concerned that I may not be passing the dictionary correctly from build_dictionary to update_points. Furthermore, is there something else I need to add to the body of UpdateCursor to ensure all features are being updated?
import arcpy point_layer = arcpy.GetParameterAsText(0) street_layer = arcpy.GetParameterAsText(1) def build_dictionary(): #Code... arcpy.AddMessage(ext_key_dict) return ext_key_dict def update_points(passed_dict): with arcpy.da.UpdateCursor(point_layer, ["OBJECTID", "RoutingStreetExtKey"]) as cursor_update: for new_row in cursor_update: obj_id = new_row if obj_id in passed_dict: new_row = passed_dict[obj_id] cursor_update.updateRow(new_row) def main(): update_points(build_dictionary()) main()