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
Solved! Go to Solution.
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:
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:
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.
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
Pedro, back to my earlier question. How do you know the code "exits" on line 15 instead of having the code complete?
In the data was nothing written...
Pedro, you marked Jake's comment as Correct, so the code is working now?
Yes it is! I am now trying to do the Add-in... which is not working already.
anyway thanks
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:
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?