B
B
benhaista2020-05-14 18:41:23
Python
benhaista, 2020-05-14 18:41:23

What's with the code, it gives: TypeError: string indices must be integers what's wrong here?

SHOPS = ({
'title':'Miarabad',
'lonm': 41.294277,
'latm': 69.270745,
'adress':'Tashkent city, Miarabadskaya street, building 35'
})

distance = []
for m in const.SHOPS :
result = Nominatim((m['latm'], m['lonm']), (lat, lon)).kilometers #error somewhere on this line
distance.append(result)
index = distance.index(min (distance))

bot.send_message(message.chat.id, 'Shop closest to you')
bot.send_venue(message.chat.id, const.SHOPS[index]['latm'], const.SHOPS[index], ['lonm'], const.SHOPS[index],['title'], const.SHOPS[index],['adress'])

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2020-05-14
@benhaista

In your code, the loop variable m contains the strings title, lonm, latm, and adress. You are iterating over the keys of the dictionary. And the string has no keys, it is impossible to execute'title'['latm']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question