I am trying to write a script where you preemptively select features and then go to the tool which calls for the feature layer and it populates fields based on certain criteria which I will design of the selected features.
I am simply trying to populate fields right now using the Update Cursor, but the field still come up blank.
here is my code so far:
input= arcpy.GetParameterAsText(0)
fields= ['Conf','Com']
with arcpy.da.UpdateCursor(input,fields) as cursor:
for row in cursor:
row[0] == '2'
cursor.updateRow(row)
del row
del cursor
Why are the selected features, or any feature for that matter not updated?
Best Answer
To expand more on @FelixIP comment, your row[0] is not assigning a value since double "==" are used with a if conditional statement for evaluating a value to be true or false. Use single "=" for committing a value change instead. Also, since your cursor is used within a with loop you do not need to delete the cursor and row objects.
Try this instead for your example:
To update only selected features you will have to make the input fc a feature layer first (use MakeFeatureLayer method) and then perform a Select Layer By Attribute or Select Layer By Location method before entering the cursor.