[Easy] Python array append

I have set up a simple array designed to take in file paths from the system.file.getTempFile() method which returns a string. However, when I attempt to run my script I will get an error that says “IndexError: index out of range: 1” and the error will point to the line printing out the array value (last line of code). I believe this is due to there not being anything with a value, or anything at all in the location of the array it’s being asked to print. Here is my whole script.

CompanyGridData = event.source.parent.getComponent("companyDisplay").data counter = 0 for counter in range(0, CompanyGridData.getRowCount()): #CompanyGridData.getRowCount() returns 3 and works fine tempFile = [] tempFile.append(system.file.getTempFile(".jpg")) print tempFile[counter]
If you want a look at the actual error report, heres a link:
http://pastebin.com/W6yCZGEA

If anyone has any ideas as to why this is happening, please let me know.

Move your declaration of the tempFile outside the loop. Also, just to clarify, you’re dealing with a list here, not an array.

Thanks Kevin, looks so obvious now.