TypeError: string indices must be integers

All other Source.Python topics and issues.
Xioto
Junior Member
Posts: 1
Joined: Sat Jun 19, 2021 4:46 pm

TypeError: string indices must be integers

Postby Xioto » Sat Jun 19, 2021 4:50 pm

So I have this bit of code that finds waveHeight and stores it as a cache, but when it reaches this section -

Code: Select all

sorted (data, key = lambda i: i['hours']) #sorts through cache_file data
print([0])
if 'waveHeight' in [0] and 'dwd' in [0]['waveHeight'] and[0]['waveHeight']['dwd'] >= 2.00: #if date and waveHeight found <2.00 then print
    print('Found')


It just gives me this error -

Code: Select all

    sorted (data, key = lambda i: i['hours']) #sorts through cache_file data
TypeError: string indices must be integers


I am in a bit of a hurry so if there is any more information you need then just ask, and I should respond soon!
User avatar
satoon101
Project Leader
Posts: 2668
Joined: Sat Jul 07, 2012 1:59 am

Re: TypeError: string indices must be integers

Postby satoon101 » Sat Jun 19, 2021 6:32 pm

The error indicates that data is not structured like you think it is. Print the value of data prior to the sorted line to verify it looks like you are intending it to.

*Edit: you might print type(data) as well to make sure the whole thing isn't a string.
Image

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 6 guests