代码示例
import cmd
class MyCLI(cmd.Cmd):
intro = 'Welcome to MyCLI. Type help or ? to list commands.\n'
prompt = '> '
def do_hello(self, arg):
'Say hello to the user'
print('Hello, world!')
def do_greet(self, arg):
'Greet someone'
print(f'Hello, {arg}!')
def do_quit(self, arg):
'Quit MyCLI'
print('Goodbye!')
return True
if __name__ == '__main__':
MyCLI().cmdloop()