Python Forum

Full Version: ARCPY using the arcpy.da.UpdateCursor
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Howdy,

I am trying to get this script to create Grid Numbers for me in a mapping fishnet,  but I am running into troubl with the error listed below  - any suggestions ?

import arcpy

arcpy.AddField_management("N:\GIS\Projects\Steve_Eastwood_Landuse\Plant_Biosecurity_Project\A0_Maps\Ao_template_Maps.gdb\Data\NTLLS_Fishnet" ,"REF","TEXT","","","5")
rowCount = 0
with arcpy.da.UpdateCursor("N:\GIS\Projects\Steve_Eastwood_Landuse\Plant_Biosecurity_Project\A0_Maps\Ao_template_Maps.gdb\Data\NTLLS_Fishnet",["OID","REF"]) as cursor:
    for row in cursor:
        leftPart = (rowCount % 4) + 1
        rightPart = ["A","B","C"][row[0] % 4]
        row[1] = str(leftPart)+str(rightPart)
        cursor.updateRow(row)


        if ((row[0]) % 64) == 63:
            rowCount = rowCount + 1
Error:
Traceback (most recent call last):   File "C:\Users\hawkinle\Desktop\STDTAS\Fishnet2.py", line 8, in <module>     rightPart = ["A","B","C"][row[0] % 4] IndexError: list index out of range [Finished in 14.8s]
Thanks Leith
Insert a print() under the for loop and see why is that
.......
    for row in cursor:
        print(row[0])
        leftPart = (rowCount % 4) + 1
        .....
SO this is ther Error I get now:

Error:
1 2Traceback (most recent call last): 3   File "C:\Users\hawkinle\Desktop\STDTAS\Fishnet2.py", line 9, in <module>     rightPart = ["A","B","C"][row[0] % 4] IndexError: list index out of range [Finished in 14.4s]
it appears to have added to the Table only the Values 1B and 1 C.  No 1A