Python Forum
ARCPY using the arcpy.da.UpdateCursor
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ARCPY using the arcpy.da.UpdateCursor
#1
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
Reply
#2
Insert a print() under the for loop and see why is that
.......
    for row in cursor:
        print(row[0])
        leftPart = (rowCount % 4) + 1
        .....
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Iterating an attribute table using Arcpy teflon 6 3,978 Oct-28-2019, 09:15 PM
Last Post: teflon
  setting environment in arcpy sunny 1 2,779 Feb-25-2019, 06:13 PM
Last Post: sunny
  ARCPY enter excel table into coded domain Just_another_lost_man 6 3,652 Feb-23-2019, 09:23 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020