I need to parse some action given by a client. The action is a simple string contained the word action: "load", "start", "pause",....
I come from C world and I am a newbie in Python. I need a switch statement and I did it with the switcher.get() function (see code below).
The problem is that this switcher doesn't recognize only the string 'load', the other strings works correctly (see output example below).
Why?
To analyze correctly the problem I give you only the switcher case beacuse the rest of the code works and it is useless for this part. I try to give directly the string 'load' to the function but it goes directly to the except zone "Command not found"
switcher={
'load': partial(load_wav,message_tocheck),
'start': partial(start_wav,message_tocheck),
'pause': partial(pause_wav,message_tocheck),
'resume': partial(resume_wav,message_tocheck),
'stop': partial(stop_wav,message_tocheck),
'reset': partial(reset_ch,message_tocheck),
'mqtt': partial(mqttrun),
'help': partial(help),
'zero':lambda:'lambda'
}
try:
func=switcher.get('load','INVALID')
return func()
except:
print('-------- COMMAND NOT FOUND --------')
OUTPUT:
- load (DOESN'T WORK):
-------- COMMAND NOT FOUND --------
- start (WORK):
Limits: A = 0, B = 8, C = 0, D = 8
Wait sample = 690
LED MATRIX ON CHANNEL 0. STIMULATION RUNNING...
- help (WORK):
---------------- help ----------------
The possible commands are:
INSERT ALL POSSIBLE TOPIC TO SUBSCRIBE
---------------- help ----------------
As you can see the only string that doesn't work is load. The problem is that I can't change the 'load' word with another one.