Hi all,
when i run this code the message "local variable 'row' referenced before assignment" appear but i think the name o the
variable and the indentation are correct.
tb = table
if tb is "RRAXERCL":
fieldsToConcat_RRAXERCL = ["CODECAVA","CODCLASS","TYPERTCR","PROFILRC","ETATRTCR"]
cursorup = arcpy.da.UpdateCursor(table,fieldsToConcat_RRAXERCL)
for row in cursorup :
row[0] = str(row[1]) + str(row[2]).rjust(2,'0') + str(row[3]).rjust(2,'0') + str(row[4]).rjust(2,'0') + str('00')
cursorup.updateRow(row)
del row
del cursorup
thank you
Solved! Go to Solution.
Just a guess, since it is not formatted (see Posting Code blocks in the new GeoNet) But my guess is that the
del row
is what is causing the issue. ....
edit...mayeb becaue it is not returning anything for cursorup....or more likely, I don't think you even need to delete the row with .da
And depending on what ArcGIS version you are using, you may want to review Accessing data using cursors—Help | ArcGIS for Desktop for your cursor.
Just a guess, since it is not formatted (see Posting Code blocks in the new GeoNet) But my guess is that the
del row
is what is causing the issue. ....
edit...mayeb becaue it is not returning anything for cursorup....or more likely, I don't think you even need to delete the row with .da
And depending on what ArcGIS version you are using, you may want to review Accessing data using cursors—Help | ArcGIS for Desktop for your cursor.
hi rebecca thank you very much,
but why del don't work here. Iuse it to clean the processus of running code
There is some info regarding locks in the help doc I included above....a snippet from it is
In Python, the lock persists until the cursor is released. Otherwise, all other applications or scripts could be unnecessarily prevented from accessing a dataset. A cursor can released by one of the following:
- Including the cursor inside a with statement, which will guarantee the release of locks regardless of whether or not the cursor is successfully completed
- Calling reset() on the cursor
- The completion of the cursor
- Explicitly deleting the cursor using Python's del statement
An edit session in ArcMap applies a shared lock to data during the edit session. An exclusive lock is applied when edits are saved. A dataset is not editable if an exclusive lock already exists.
Using the first type, the "with" statement, tends to be the preferred method I've seen in the forums. There are some good examples showing this on that same help document. I hope that helps explain "why".