On Mon, Mar 8, 2010 at 7:40 AM, Steven Bethard <steven.beth...@gmail.com> wrote: > On Sun, Mar 7, 2010 at 11:49 AM, Guido van Rossum <gu...@python.org> wrote: >> On Sun, Mar 7, 2010 at 4:29 AM, Neal Becker <ndbeck...@gmail.com> wrote: >>> Brian Curtin wrote: >>> >>>> On Fri, Mar 5, 2010 at 12:51, Neal Becker <ndbeck...@gmail.com> wrote: >>>> >>>>> I generally enjoy argparse, but one thing I find rather >>>>> ugly and unpythonic. >>>>> >>>>> parser.add_argument ('--plot', action='store_true') >>>>> >>>>> Specifying the argument 'action' as a string is IMO ugly. >>>>> >>>> >>>> What else would you propose? >>>> FWIW, this is the same in optparse. >>> >>> I would have thought use the object itself, instead of a string that spells >>> the object's name. >> >> What object? How would you write the example instead then? > > In argparse, unlike optparse, actions are actually defined by objects > with a particular API, and the string is just a shorthand for > referring to that. So: > > parser.add_argument ('--plot', action='store_true') > > is equivalent to: > > parser.add_argument('--plot', argparse._StoreTrueAction)
Sorry, that should have been: parser.add_argument('--plot', action=argparse._StoreTrueAction) > > Because the names are so long and you'd have to import them, I've left > them as private attributes of the module, but if there's really > demand, we could rename them to argparse.StoreTrueAction, etc. > > Steve > -- > Where did you get that preposterous hypothesis? > Did Steve tell you that? > --- The Hiphopopotamus > -- Where did you get that preposterous hypothesis? Did Steve tell you that? --- The Hiphopopotamus _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com