1

I've been trying to create a python script that will update certain fields in the arcgis attribute table. I have attempted to do this by using the update cursor to update a field based on another field value found in the same row.

Here is the code I used:

import arcpy
fc = "C:\Users\maureen\Documents\ArcGIS\EDRN\EDRN_LINK.shp"
fields = ["FID", "RIVERNAME"]
with arcpy.da.UpdateCursor(fc, fields) as cursor:
 for row in cursor:
 if row[0] = 4401:
 row[1] = "Aire"
 cursor.updateRow(row)

Unfortunately, when I run this in ArcMap it returns the following syntax error:

Parsing error SyntaxError: invalid syntax (line 9) 

Does anyone have any idea where I'm going wrong? I've researched this script a fair bit and can't see any obvious errors.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jun 20, 2014 at 14:40
3
  • I suppose you ment if row[0] == 4401: // ... You forgot the double-equal-sign, that´s it I think Commented Jun 20, 2014 at 14:49
  • In addition to the answers below, make sure the "RIVERNAME" field is a text field. Commented Jun 20, 2014 at 15:07
  • from @Aaron above - I run into Subtypes sometimes and bang my head on the wall until I realize I'm looking for an integer value. The == is the main problem though. Commented Jun 21, 2014 at 3:36

1 Answer 1

9

For comparison of 'equals' you need to use a double equals sign '=='

if row[0] == 4401:
 row[1] = "Aire"
 cursor.updateRow(row)

A single equals sign is the assignment operator in python.

answered Jun 20, 2014 at 14:48

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.