'How can I parse the variable number of arguments to a function? [duplicate]

I want to pass a variable number of arguments to a function, the first argument represents a command, and the remaining arguments represent the arguments to the command. For example:

def do(*argv):
    command = argv[0]

    match command:
        case "doNothing":
            print("do nothing")
        case "create":
            arg = argv[1]
            print(arg)
        case "add":
            arg1 = argv[1]
            arg2 = argv[2]
            print(arg1 + arg2)
        case default:
            return "something wrong with the input to do()"

do("create", [1,2])

and run it

$ python ./my.py
  File "/home/t/my.py", line 8
    match command:
          ^
SyntaxError: invalid syntax

How can I parse the variable number of arguments?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source