Search code examples
pythoncommand-line-argumentsoptional-parametersargparse

python argparse to handle arbitrary numeric options (like HEAD(1))


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.


Solution

  • Neither agrparse nor optparse supports this.