I'm a Python beginner, I'm doing a risk analysis with a point feature, and I'm trying to write a script that allow me to update a field (proximity) based on different numeric values within different fields.

Each field (field_1, field_2, field_3, field_4) has just one possible value ( respectively 1, 2, 3, 4) and in each row there is recorded only one of these different values. Example: If in a row there's 1 in field_1 it's impossible to find other values in the other fields.

I would like to put everything in one field (proximity) to indicate the risk level.

I tried to run the following script to test only with field_1, but it's not updating, it's just printing "Nothing for each row".

with arcpy.da.UpdateCursor("point", "proximity") as cursor: 
for row in cursor: 
    with arcpy.da.SearchCursor("point", "field_1") as scursor:
        for row in scursor: 
            if row[0] == 1:
            print ("Nothing")
  • For now I have solved doing 4 different layer selection by attribute + calculate field for the new field, but I think there is something much simpler...
    – Carl
    Commented Feb 15, 2020 at 15:06
  • 1
    Nesting update and search cursors is usually unnecessary, but if it is required, so is not using conflicting variables. Unfortunately, you don't have enough code or verbiage to determine what it is that you want to do.
    – Vince
    Commented Feb 15, 2020 at 15:51
  • 1
    Can you add a screenshot showing you table and your expected output. I dont understand your description
    – Bera
    Commented Feb 15, 2020 at 16:18
  • 1
    The code that you have presented looks like it would give an indentation error on its second line.
    – PolyGeo
    Commented Feb 15, 2020 at 19:16

1 Answer 1


Try something like:

import arcpy
fc = 'points1'
fields = ['Field1','Field2','Field3','Result']
with arcpy.da.UpdateCursor(fc,fields) as cursor:
    for row in cursor:
        row[-1] = max(row[:-1])

You might need to change max(row[:-1]). For example if you can have None values in some field, it will fail. Then try max([v for v in row[:-1] if v is not None])

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.