UpdateCursor no error shown

593
9
Jump to solution
03-23-2020 09:45 AM
PSGeo
by
New Contributor II

Hi Gents,

I am using Arcmap 10.5.

Can someone tell me what is wrong here?

When it gets to line 15 it simply exits with no error and no update... 

 if count<>"0":     # only feature classes with features



                    with arcpy.da.UpdateCursor(fc,("BDV"),"*") as cur : 
                        for row in cur:
                            row[0]=date
                            cur.updateRow(row)
                    
                    del row


                    with arcpy.da.UpdateCursor(fc,("BIN"),"*") as cursor_Name: 

                        for prow in cursor_Name:
                            
                            prow[0]=NN_code
                            cursor_Name.updateRow(prow)

                    del prow
0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor

Hey Pedro,

For the second parameter in your cursors, the fields will be specified with the following ["field name"].  Try updating each cursor with the following:

with arcpy.da.UpdateCursor(fc,["BDV"]) as cur : 

and

with arcpy.da.UpdateCursor(fc,["BIN"]) as cursor_Name: 

View solution in original post

9 Replies
JakeSkinner
Esri Esteemed Contributor

Hey Pedro,

For the second parameter in your cursors, the fields will be specified with the following ["field name"].  Try updating each cursor with the following:

with arcpy.da.UpdateCursor(fc,["BDV"]) as cur : 

and

with arcpy.da.UpdateCursor(fc,["BIN"]) as cursor_Name: 
JoshuaBixby
MVP Esteemed Contributor

Although the OP's syntax around field names is awkward, it will work.  If there is only a single field for the cursor, it can be passed as a string, i.e., it doesn't have to be in a list, which is what the OP is doing here.  The parentheses around the text in the OP's code serve no purpose because they are not making a tuple (for a tuple, one would have to put a comma after the item).  That said, the sequence of field names can be passed as a tuple, it just isn't idiomatic.

Also, the random asterisk for the SQL WHERE clause will work, but again is not idiomatic to ArcPy.

Although the OP's code will work, its uncommon structure gives the impression it works as much by chance as on purpose.

PSGeo
by
New Contributor II

Hi Joshua,

I understand for a programmer this looks very messy... but I am not a programmer and I never had lessons on it. I just have a need and I have seen python as a solution and I try it. Sometimes works sometimes not, sometimes I got blocked for days with very simple things such as "tab" in the wrong location.

For this case, I just want to do a button to be used in arcmap that populates a field with a user input date and update another field with the name of the mxd. For the moment I will see how to create buttons for this stuff.

Any suggestion is welcome.

cheers

P

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Pedro, back to my earlier question.  How do you know the code "exits" on line 15 instead of having the code complete?

0 Kudos
PSGeo
by
New Contributor II

In the data was nothing written... 

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Pedro, you marked Jake's comment as Correct, so the code is working now?

0 Kudos
PSGeo
by
New Contributor II

Yes it is! I am now trying to do the Add-in... which is not working already.

anyway thanks

0 Kudos
RandyBurton
MVP Regular Contributor

Is there a reason you are using count as text (number inside quotes)  and not a number?  How is count being set?

if count<>"0":     # "0" is a text string

# vs

if count <> 0:  #  >0  assuming negative numbers wouldn't happen
# or
if count: ‍‍‍‍‍‍‍
0 Kudos
JoshuaBixby
MVP Esteemed Contributor

When it gets to line 15 it simply exits with no error and no update..

How do you know it is exiting and not completing the code?