Using cmd for creating command-line applications
There are several ways of creating interactive applications. The
Using input() and getpass() for user input
recipe looked at functions such as input()
and getpass.getpass()
. The
Using
argparse to get command-line input
recipe showed how to use argparse
to create applications with which a user can interact from the OS command line.
We have a third way to create interactive applications using the cmd
module. This module will prompt the user for input, and then invoke a specific method of the class we provide.
This is related to material in Chapter 7, More Advanced Class Design . We'll add features to a class definition to create a unique subclass.
Here's how the interaction will look, we've marked user input like this: "help
":
Starting with 100
Roulette> help
Documented commands (type help <topic>):
========================================
bet help
Undocumented commands:
======================...