Currently my code looks like this. It allows me to parse multiple parameters my program script gets. Is there a different way that is closer to \'best practices\'? I haven\'t se
You could supply a custom action for an argument by, and I quote:
passing an object that implements the Action API. The easiest way to do this is to extend argparse.Action, supplying an appropriate
__call__
method. The__call__
method should accept four parameters:
- parser: The ArgumentParser object which contains this action.
- namespace: The namespace object that will be returned by
parse_args()
. Most actions add an attribute to this object.- values: The associated command-line args, with any type-conversions applied.(Type-conversions are specified with the type keyword argument to
add_argument()
.- option_string: The option string that was used to invoke this action. The option_string argument is optional, and will be absent if the action is associated with a positional argument.