June 2019
Beginner to intermediate
770 pages
19h 24m
English
We will define a simple on–off option with a one-letter short name or a longer name. We should also provide an explicit action. We might want to provide a destination variable if we omit the longer name, or if the longer name is unpleasant as a Python variable. Let's set this up using the following code:
parser.add_argument( '-v', '--verbose', action='store_true', default=False)
This will define the long and short versions of the command-line option. If the option is present, the action will set the verbose option to True. If the option is absent, the verbose option will default to False. Here are some common variations of this theme:
Read now
Unlock full access