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

argparse, command-line-arguments, optional-parameters, python

Solution

Neither agrparse nor optparse supports this.

Problem

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.

Original source