June 2019
Beginner to intermediate
770 pages
19h 24m
English
We define argument lists with a name that has no - decoration and a piece of advice in the nargs= parameter. If the rule is one or more argument values, we specify nargs="+". If the rule is zero or more argument values, we specify nargs="*", as shown in the following code. If the rule is optional, we specify nargs="?". This will collect all other argument values into a single sequence in the resulting namespace:
parser.add_argument( "filenames", action="store", nargs="*", metavar="file...")
When the list of filenames is optional, it generally means that STDIN or STDOUT will be used if no specific filenames are provided.
If we specify a nargs= value, then the result becomes a list. If we specify nargs=1, then the resulting ...
Read now
Unlock full access