I am attempting to populate a new field with a "Y" or "N" based on whether two integer fields are equal. My code seems like it should work, but when I run it, it does not update the field (the field is still ). I have double checked that the inputs are correct and I have reloaded the table to make sure it was not an updating issue.

inTable = os.path.join(env.workspace, "pivotTableTEMP")
with arcpy.da.UpdateCursor(inTable, ["dmready", "total_records", "ALLREADY"]) as cursor:
    for row in cursor:
        if row[0] == row[1]:
            row[2] == "Y"
            row[2] == "N"

The dmready and total_records fields are both integers and the ALLREADY field is string.

Vince's advice worked perfectly for the above code. However, I added another conditional statement and it is not filling properly. Here is my new code:

inTable = os.path.join(env.workspace, "pivotTableTEMP")
with arcpy.da.UpdateCursor(inTable, ["dmready", "total_records", "dm_stat", "ALLREADY"]) as cursor:
    for row in cursor:
        if row[0] == row[1] and row[2] == "Ready for DM":
            row[3] = "Y"
            row[3] = "N"
            cursor.updateRow(row) # could also delete here if

The result of this code is that it fills all records of the ALLREADY field with "N" when there are several that fit the conditions for "Y". Any thoughts?

closed as off-topic by Vince, Midavalo, Andre Silva, PolyGeo Jul 20 '16 at 22:16

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This problem cannot or can no longer be reproduced. Changes to the system or to the asker's circumstances may have rendered the question obsolete, or the question does not include a procedure to enable potential answerers to reproduce the same symptoms. Such questions are off-topic as they are unlikely to help future readers, but editing them to include more details can lead to re-opening." – Vince, Midavalo, Andre Silva, PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    Your assignment statements aren't -- they're no-op equivalence tests. Use = not == for assignment. – Vince Jul 20 '16 at 17:56
  • That worked perfectly. Can't believe I didn't catch that. Thank you, Vince! – mmoore Jul 20 '16 at 18:08
  • 1
    You can also structure the logic so the updateRow is outside the if. In fact, you can use the ternary logic operator row[2] = "Y' if row[0] == row[1] else "2" – Vince Jul 20 '16 at 19:32
  • Sounds like you've got some un-handled conditions in the data being tested in the first if. I'd look through the data and make sure you're covering all your bases (spelling variances in "ALLREADY", that sort of thing). – Kevin Jul 20 '16 at 20:30
  • If you have moved onto a new issue then I suggest researching it as such, and if you remain stuck, then to ask it as a new question. – PolyGeo Jul 20 '16 at 22:17

Browse other questions tagged or ask your own question.