Updating rows with an UpdateCursor

5042
18
04-05-2016 01:53 AM
MalgorzataMendela
New Contributor III

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?error.png     

0 Kudos
18 Replies
MalgorzataMendela
New Contributor III

How to update the value of a string type attribute?
After running the following script, there is no answer
Could you please help me?
error.png

0 Kudos
AdrianWelsh
MVP Honored Contributor

Hi Malgorzata,

When you run this, are you getting an error? Or is it not updating any of the rows?

It looks like there may be an issue with your if statement. What are you wanting to see in column [0]? The single quotes are throwing me off. Can you explain that more?

Also, you may want to consider adding your code to the syntax editor by going to "Use advanced editor", click on the double arrows, choose Syntax Highlighting, and choose Python.

PythonSyntaxGeoNet.PNG

MalgorzataMendela
New Contributor III

I would like to change the value of the attribute "AREA" if the value of the attribute "NAZ" is "Obodowo"

0 Kudos
DanPatterson_Retired
MVP Emeritus

if row[1] = "Obodowo":    # row[1] is Naz ???

    row[2] = 170 # since row[2] is Area

but if area is a text field then use "170"

You might want to write out what for the data currently are in and what you want it to look like

0 Kudos
curtvprice
MVP Esteemed Contributor

String variables accessed within a cursor like this don't need extra quotes:

if row[0] == "Obodowo" 

should do it.

0 Kudos
MalgorzataMendela
New Contributor III

I have also tried to use such a line of code previously, but it doesn't help.
There is still no result and no error message.
Have you got maybe other ideas?  

0 Kudos
NeilAyres
MVP Alum

Why not put this into a script, instead of typing it out each time.

Just open IDLE or whatever you are using, open a new file, put the code there, and save.

You can run it within the interpreter.

Then post the entire code here using the python syntax highlighter.

Perhaps a piece of data as well.

Does that workspace exist? Can the script see it? Its has spaces in the path which is generally a bad thing, but I don't think that is the issue here.

Do you have write permissions in that workspace?

And, what is that workspace anyway? A folder? A fgdb (doesn't look like it)?

If this is a coverage (still), you will not be able to overwrite a system variable like that. And, not sure if Update cursors would work anyway.

MalgorzataMendela
New Contributor III

I have put the code into IDLE and check the module. It has turned out that there should be "miasta0_kujpom.shp" instead of "miasta0_kujpom"
Thank you for your suggestions.

0 Kudos
NeilAyres
MVP Alum

Kindly mark this post as answered.

0 Kudos