i have implemented a function:
def postback(i,user,tval):
"""functie ce posteaza raspunsul bazei de date;stringul din mesaj tb sa fie mai mic de 140 de caractere"""
result = {
1:api.PostDirectMessage(user,'Trebuie sa-mi spui si marca pe care o cauti'),
2:postmarket(user,tval),
3:api.PostDirectMessage(user,'Imi pare rau, dar nu stiu unde poti gasi aceste tipuri de smantana: %s' % tval)}
return result.get(i)
but it does not work as a case alternative(from c++) it executes all 3 cases no matter wha i try…i’m a begginer so there might be another error, so please help!p.s. please don’t tell me that the if…else.. is the only alternative cause i know this can work
It executes all three cases because you define the
resultdict that way! You call all three functions and assign them to the keys 1, 2, 3.What you should instead is something like this:
Here I define small wrapper functions and store those in the dict instead. You then pick the right function and call on this one function.