This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Chris.Bruner
Recipients Chris.Bruner, docs@python, paul.j3, r.david.murray
Date 2014-07-29.19:53:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <CAEdEUw7pE=j-MTip3iGJmV1ju+6WB+q2H7qFm8Yu=7trFWzMKA@mail.gmail.com>
In-reply-to <1406326623.31.0.332890989494.issue22049@psf.upfronthosting.co.za>
Content
Just had a chance to try this, and this does exactly what I wanted from
"type=". Thank you!

On Fri, Jul 25, 2014 at 4:17 PM, paul j3 <report@bugs.python.org> wrote:

>
> paul j3 added the comment:
>
> What you want is a custom Action rather than a custom Type.
>
> from the documentation:
>
>     >>> class FooAction(argparse.Action):
>     ...     def __call__(self, parser, namespace, values,
> option_string=None):
>     ...         print('%r %r %r' % (namespace, values, option_string))
>     ...         setattr(namespace, self.dest, values)
>
> 'values' will be the list ['1','2','3'], which you test and manipulate,
> before finally saving it to the 'namespace'.
>
>     ret = (int(values[0]), int(values[1]), float(values[2]))
>     setattr(namespace, self.dest, ret)
>
> Setting 'nargs=3' ensures that this action will always get a 3 item list.
>  If the parser can't give it 3 items, it will raise an error rather than
> call your Action.
>
> 'optparse' passed the remaining argument strings to Option's callback,
> which could consume as many as it wanted.  'argparse' does not give the
> Actions that power.  There is a fundamental difference in the parsing
> algorithm.
>
> ----------
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue22049>
> _______________________________________
>
History
Date User Action Args
2014-07-29 19:53:26Chris.Brunersetrecipients: + Chris.Bruner, r.david.murray, docs@python, paul.j3
2014-07-29 19:53:26Chris.Brunerlinkissue22049 messages
2014-07-29 19:53:26Chris.Brunercreate