0
testingdays = testingData.getMeasurements()

for day in testingdays:
	dayValues = []
	dayValues[0].append(day.tempMean)
	dayValues[1].append(day.tempMax)
	dayValues[2].append(day.tempMin)
	dayValues[3].append(day.dewPoint)
	dayValues[4].append(day.humidMean)	
	dayValues[5].append(day.humidMax)
	dayValues[6].append(day.humidMin)
	dayValues[7].append(day.pressure)
	dayValues[8].append(day.meanWindSpeed)
	dayValues[9].append(day.maxWindSpeed)
	dayValues[10].append(day.maxGustSpeed)
	dayValues[11].append(day.visibility)

this is my code and when i try to run it i get the error message:

"Traceback (most recent call last):
File "main.py", line 166, in <module>
dayValues[0].append(day.tempMean)
IndexError: list index out of range"

Each day has 12 classes/elements so the list index shouldn't be out of range!
I've got code just before this which pops items from a list, but this part shouldn't be involved with that so i'm not sure why i get this error message
sorry, not sure if i've posted enough information to get help with this!
Thanks

4
Contributors
5
Replies
8
Views
5 Years
Discussion Span
Last Post by pyTony
0

dayValues is an empty list when you start, so dayValues[0] isn't yet in dayValues and 0 is an index out of range.
You probably want dayValues = [[]]*12 at line 4

Edited by griswolf: n/a

0

just append your data;

testingdays = testingData.getMeasurements()
dayValues = []
for day in testingdays:
    dayValues.append(day.tempMean)
    dayValues.append(day.tempMax)
    dayValues.append(day.tempMin)
    dayValues.append(day.dewPoint)
    dayValues.append(day.humidMean)    
    dayValues.append(day.humidMax)
    dayValues.append(day.humidMin)
    dayValues.append(day.pressure)
    dayValues.append(day.meanWindSpeed)
    dayValues.append(day.maxWindSpeed)
    dayValues.append(day.maxGustSpeed)
    dayValues.append(day.visibility)

And you are ready to go. And dont put or initialize list in a loop ok?
;)

0

thanks that helps a lot, i tried the second option, works now,
and i need the list to be initialised in a loop because i need it to reset for each day (there's more code below it within the for loop)

0

But that is not the logic.
You need to reset the list container or delete.

But you dont have to initialize a list in a loop.
no good ;)

0

I have difficulty understanding why you do not leave values in the object. From variable name I would expect to be list of measurement objects.

Edited by pyTony: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.