I'm running a script that parses points from a flat database structure into individual feature classes with related tables.
A search cursor runs through and stores each field's data in a variable that I use to create points with using an insert cursor. After each loop, I'd like to clean up the variables so that data from the last loop can't be used in each loop thereafter.
I've got an array that I've hard coded with each variable name that I loop through to delete each one. I've checked these var names 100 times to make sure they're correct (even copied them from where they're declared and pasted them into the array).
I'm getting an error:
IndexError: list index out of range
I'm using len() to find the length of the array, so I can't imagine how it could be out of range.
# Clean-up Variables
cleanup = [ptGeom, ptName, ptType, ptDate, active, ptComm, fdDate, fdCheck, surType,
fdType, special, lure1, lure2, fdComm, photo, signType, signAmt, platSet,
platSign, trapType, trapAct, trapStat, capSpec, capSex, capType, trapSet]
length = len(cleanup) - 1
for i in range(0, length):
print i
if cleanup[i]:
del cleanup[i]
The error is after it prints 19 (trapType) -- which is a null value according to the attribute table. The loop isn't having trouble with any of the other null values that it encounters before this line.
cleanup, populates it with the current values of 26 variables (not their names), and then attempts to delete the non-null entries. I would guess that each successful deletion shortens the length ofcleanup. By the time you get totrapType, you have probably deleted seven entries, whence index 19 falls out of range. Second, it doesn't matter: this code won't do a thing to those 26 variables; it only modifiescleanup. – whuber♦ Apr 10 '12 at 20:31