0

I am new to making switch statements in python. I keep getting the error auth isn't identified in the following code. The argument of the switch statement should be the first element in msgparam which is a list of strings

class SendMessage :

    def Auth_process(message):
        val2 =0
        for flag in message:
            if(flag == '-raw'):
                val1 |= 0x01
            elif(flag == '-v'):
                val1 |= 0x02  
            elif(flag == '-p'):
                val1 |= 0x04
            elif( flag == '-smple'):
                val1 = 0x08
            else:
                val1 = val1
        return Auth_process( val1, val2)


    def command_process(arg, *args):
       switcher ={
            auth : Auth_process,  ////error occurs here
              rd : read,
        }
       func = switcher.get(arg)
       return func(args)

    def __init__(self, cmd):
        status = False
        value1= 0
        value2= 0
        result = '"This commandself is invalid please check arguments for appropriate size or invalid characters";'
        msgparam = cmd.split(' ')
        print(msgparam)
        self.command_process(msgparam[0], msgparam)

if __name__ == '__main__':
    data =  SendMessage("auth -v -raw")

1 Answer 1

1

Your dictionary keys are set as variables (that are undefined when you try to reference them, as the error says) instead of strings. You want:

switcher ={
    'auth' : Auth_process,
    'rd' : read,
}

You'll also need to make sure that read is a defined method of the class.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.