0

I'm trying to use the updateCursor in ArcGIS Pro 2.4 to populate a new field in my table and can't get it to work. Situation is like this: I have a table with many fields. One of those fields is "Status1". This field contains text values (for example: "No", "Yes", "ABC123" or nulls). What I need to do is to take everything that is a "No" and put it as "Not Completed" while the rest would be just "Completed" in a new field called "Status2"

My code probably is completely wrong. I have no idea how to access a specific field within a featureclass.

with arcpy.UpdateCursor(FC, fields) as cursor:
    for row in cursor:
        if Status1[0] = 'No':
            Status2[0] = 'Not Completed'
        else:
            Status2[0] = 'Pending'
    cursor.updateRow(row)
3
  • If you are using ArcGIS 10.1 and above, it is better to use arcpy.da.UpdateCursor. Now It depends on how you ordered your field names inside variable fields, and with if statement, you need to use == not one = and Status1[0] and Status2[0] should be row[0] and row[1] assuming `fields = [Status1, Status2]'.
    – ahmadhanb
    Commented Sep 18, 2019 at 19:27
  • I'm on Pro. About the "==" it was just a typo Commented Sep 18, 2019 at 19:32
  • @user1503110 that’s an important detail that you should edit into your question.
    – PolyGeo
    Commented Sep 18, 2019 at 21:03

1 Answer 1

1

As mentioned in the comments make use of a data access cursor. Use the two status fields as your field input and perform an if logic check.

with arcpy.da.UpdateCursor(FC, ["Status1", "Status2"]) as cursor:
    for stat1, stat2 in cursor:
        if stat1 == "No":
            stat2 = "Not Completed"
        else:
            stat2 = "Completed"
        row = (stat1, stat2)
        cursor.updateRow(row)
3
  • Thanks for your reply. I changed the code to data access and tried this code but I keep getting an error with cursor.updateRow(row). Also, for some reason I'm geting warnings in line 2 for stat2 ("defined withough usage) and line 7 for both fields "cannot be defined" Commented Sep 18, 2019 at 20:04
  • It worked in the end. One of my indentations was wrong. Thanks a lot!!! Commented Sep 18, 2019 at 20:59
  • Sure thing. Please mark the answer as correct (the check mark) Commented Sep 18, 2019 at 22:48

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.