As part of a larger project i'm looking to add multiple fields to a shapefile using an index. This is the snippet in question:
listFields = [['ITEM', 'TEXT'], ['SYSTEM', 'TEXT'], ['WATERCOURCE_BANK', 'TEXT'], ['AIMS_REF', 'TEXT'],
['CHAINAGE', 'TEXT'], ['GRID_REF', 'TEXT'], ['CUT', 'TEXT'], ['LENGTH_KM', 'TEXT'], ['COMMENTS', 'TEXT']]
print("Adding fields")
for addField in listFields:
print(" ...{}".format(addField[0]))
arcpy.AddField_management('table_stamp', addField[0], addField[1], addField[2], addField[3], addField[4],
addField[5], addField[6], addField[7], addField[8])
I'm getting the following error, pointing at the line of code above:
IndexError: list index out of range
As far as I can tell I have got my Indexing right. Nine fields to add so the indexes should be 0 to 8.
Anybody have any idea what the issue might be?
addField
only has 2 elements. The references toaddfield[2]
and above are what are causing the IndexError.