'calling methods as command line arguments in the cmd

I have been dealing with this question for quite a time, so I decided to ask directly here for explanations/ what and where to read from. From university we are doing a project where we use python and the cmd class to call the methods as arguments to the command line. The lecturer has provided us with some example on how it could work and so on. However he didn't fully explained some details that I still miss about the arguments and how in general you can call the function as an argument in the command line prompt.

Here I will provide a shortened version of the code which he has written, as the general methods are the only thing included here in order to explain the situation in simpler manner.

import cmd
class Multiplayer(cmd.Cmd):
   
    def __init__(self):
        """Init the object."""
        super().__init__()
        self.dice = dice.Dice() # dice object to call the roll() later
        self.player1 = player.Player(1) # score = 0, index = 1
        self.player2 = player.Player(2) # score = 0, index = 2
        self.playerTurn = player.Player(1) # score = 0, index = 1

    def do_start(self, _): #here is the part i dont fully understand 
        """start a new game"""
        print("You have started a new game.\n")
        print("""
        Welcome to the game. Type help or ? to list commands.\n
        To set both players names, type: 'set_names' \n""")
        self.__init__() #calling constructor so the new game starts

    def do_exit(self, _):
        """Leave the game."""
        print("press 'l' to leave game, press 's' to start a new one")
        comand = input()
        if comand == 'l':
             return True
        elif comand == 's':
             self.do_start(self)
        else:
             print("unknow syntax")
             self.do_exit(self)

    def do_EOF(self, arg):
        """Leave the game."""
        return self.do_exit(arg)

When I type "start" this function is called byt the cmd and executed. In general does the "do_" part infront of the function name has to do something with the command line itself? Why do we need this second argument (the underscore dash)? And what is it for?

(I have tried to remove it but then i typed in "-help", couldn't see the command.) I have checked other's classmates codes and they have used other words instead of underscore dash.

If you provide me with some sources/explanations so I can get a better grasp of this concept, it would be really appreciated.

Thanks in advance for the replies. Cheers!



Sources

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

Source: Stack Overflow

Solution Source