Is there a way to trick argparse
into accepting arbitrary numeric arguments like HEAD(1)
?
head -5 test.txt
is equivalent to
head -n 5 test.txt
My current approach is to use parse_known_args()
and then handle the remainder, but I'd wish there was something a tad more elegant.
To add an optional argument, simply omit the required parameter in add_argument() . args = parser. parse_args()if args.
The add_argument() method action - The basic type of action to be taken when this argument is encountered at the command line. nargs - The number of command-line arguments that should be consumed. const - A constant value required by some action and nargs selections.
Neither agrparse nor optparse supports this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With