I would like to update one value of the attribute called "AREA" with the function UpdateCursor, but as I have run the script, I have received a syntax error message.
Could you please help me to solve this problem?
This looks like an old coverage or something imported into a db.
The fields "AREA" and "PERIMITER" are system variables, so they should not be updated anyway.
If you look right along the attribute table do you have "SHAPE_AREA" or something like that.
That will contain the current area in the units of the feature.
Unfortunately, the same problem occurs when I try to change the value of the variable, which isn't a system ones, so this is not the case. Please have a look at the following example:
You seem to be missing the double equal sign in the if statement again.
if row = 114:
if row == 114:
Which would explain why you're getting an error at line 6.
Clicked submit too soon and can't edit my previous comment on the mobile GeoNet site...
The print statement after yo needs to be indented 4 spaces further than the except clause. Move the except back until it's indented the same as the try, then move the print back. Should look something like :
with arcpy.da.UpdateCursor etc...
for row etc...
except Exception as e:
Better yet... Remove the try/except completely so you get a proper exception traceback if something goes wrong.
Thank you Luke... and to illustrate his point with a simple example
>>> print(something) Traceback (most recent call last): File "<interactive input>", line 1, in <module> NameError: name 'something' is not defined >>> print(something) Traceback (most recent call last): File "<interactive input>", line 1, in <module> NameError: name 'something' is not defined >>> try: ... print(something) ... except Exception as e: ... print(e.message) ... name 'something' is not defined >>>
Hmmmmm look kind of the same to me.
Learn how to interpret error messages. You will always get something that you can't decipher easily even with try except blocks (and trackback in different versions)
Your code will be cleaner and indentation errors etc will be less of an issue