2

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?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jan 18, 2016 at 0:28
1
  • 5
    Do not del row. row[0]='2'. Also do not use word input, do not del cursor Commented Jan 18, 2016 at 0:45

1 Answer 1

5

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:

fc = arcpy.GetParameterAsText(0)
fields = ['Conf','Com']
 with arcpy.da.UpdateCursor(fc,fields) as cursor:
 for row in cursor:
 row[0] = '2'
 cursor.updateRow(row)

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.

answered Jan 18, 2016 at 0:54
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.