Select to view content in your preferred language

Update Cursor - update multiple fields based on one field

977
1
11-02-2021 08:04 AM
BillJacobs
Emerging Contributor

Hello,

 

I made this update cursor script to update a three fields based on one field, but it doesn't update any. Ive checked and all field names are currect. Any advice?

 

Thanks!

updateFields = ["BarrierTyp", "StructureCategory", "StructureClass", "Diversion"]
with arcpy.da.UpdateCursor(schemaone, updateFields) as cursor:
    for row in cursor:
        if row[0] is None:
            continue
        if row[0] == "Water Diversion":
            row[1] == 3
            row[2] == 31
            row[3] == 1
        elif row[0] == "Manmade Dam":
            row[1] == 9
            row[2] == 0
            row[3] == 0
        else:
            row[1] == 0
            row[2] == 0
            row[3] == 0
        cursor.updateRow(row)

 

0 Kudos
1 Reply
BlakeTerhune
MVP Regular Contributor

Change the equality statements (==) to assignment (=) for everything that's not part of an if statement.

updateFields = ["BarrierTyp", "StructureCategory", "StructureClass", "Diversion"]
with arcpy.da.UpdateCursor(schemaone, updateFields) as cursor:
    for row in cursor:
        if row[0] is None:
            continue
        if row[0] == "Water Diversion":
            row[1] = 3
            row[2] = 31
            row[3] = 1
        elif row[0] == "Manmade Dam":
            row[1] = 9
            row[2] = 0
            row[3] = 0
        else:
            row[1] = 0
            row[2] = 0
            row[3] = 0
        cursor.updateRow(row)