Re: [Python-Dev] argparse ugliness

2010-03-10 Thread Fred Drake
On Wed, Mar 10, 2010 at 7:46 AM, Nick Coghlan wrote: > All of this discussion about the class names is ignoring the main > benefit of using the string names: Another benefit of strings is that data-driven argparse configuration will usually be slightly simpler. Some of us find things like that u

Re: [Python-Dev] argparse ugliness

2010-03-10 Thread Eric Smith
Nick Coghlan wrote: Greg Ewing wrote: Steven Bethard wrote: 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. What's wrong with just StoreTrue?

Re: [Python-Dev] argparse ugliness

2010-03-10 Thread Nick Coghlan
Greg Ewing wrote: > Xavier Morel wrote: >> So you'd have to write add_argument('--plot', >> action=actions.store_true) which is straight from the department of >> redundant redundancies. > > This could easily be fixed with > > from argparse.actions import store_true Converting argparse from a mo

Re: [Python-Dev] argparse ugliness

2010-03-10 Thread Nick Coghlan
Greg Ewing wrote: > Steven Bethard wrote: > >> 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. > > What's wrong with just StoreTrue? All of

Re: [Python-Dev] argparse ugliness

2010-03-09 Thread Robert Kern
On Tue, Mar 9, 2010 at 11:31, R. David Murray wrote: > On Mon, 08 Mar 2010 15:35:46 -0600, Robert Kern wrote: >> On 2010-03-08 15:20 PM, Greg Ewing wrote: >> > Mark Russell wrote: >> >> Boolean flags are a common enough case that I'd be inclined to add a >> >> wrapper method, >> >> >> >> parser.a

Re: [Python-Dev] argparse ugliness

2010-03-09 Thread R. David Murray
On Mon, 08 Mar 2010 15:35:46 -0600, Robert Kern wrote: > On 2010-03-08 15:20 PM, Greg Ewing wrote: > > Mark Russell wrote: > >> Boolean flags are a common enough case that I'd be inclined to add a > >> wrapper method, > >> > >> parser.add_bool_argument('--plot') > > > > +1, this looks good. > > I

Re: [Python-Dev] argparse ugliness

2010-03-08 Thread Ben Finney
David Stanek writes: > On Mon, Mar 8, 2010 at 10:40 AM, Steven Bethard > wrote: > >  parser.add_argument ('--plot', action='store_true') […] +1. > Any reason not to do something like: > > from argparse import actions > ... > parser.add_argument('--plot', actions.store_true) > > Basically

Re: [Python-Dev] argparse ugliness

2010-03-08 Thread Greg Ewing
Xavier Morel wrote: So you'd have to write add_argument('--plot', action=actions.store_true) which is straight from the department of redundant redundancies. This could easily be fixed with from argparse.actions import store_true An option would be parser.add(actions.StoreTrue('--plot'

Re: [Python-Dev] argparse ugliness

2010-03-08 Thread Robert Kern
On 2010-03-08 15:20 PM, Greg Ewing wrote: Mark Russell wrote: Boolean flags are a common enough case that I'd be inclined to add a wrapper method, parser.add_bool_argument('--plot') +1, this looks good. I've added it to the argparse bugtracker, along with my suggested spelling add_flag():

Re: [Python-Dev] argparse ugliness

2010-03-08 Thread Greg Ewing
Steven Bethard wrote: 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. What's wrong with just StoreTrue? -- Greg ___

Re: [Python-Dev] argparse ugliness

2010-03-08 Thread Greg Ewing
Mark Russell wrote: Boolean flags are a common enough case that I'd be inclined to add a wrapper method, parser.add_bool_argument('--plot') +1, this looks good. -- Greg ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.or

Re: [Python-Dev] argparse ugliness

2010-03-08 Thread Guido van Rossum
On Mon, Mar 8, 2010 at 9:17 AM, Ron Adam wrote: > I like the strings.  They are simple and easy to use/read and they don't > have to be created or imported before the parser is defined. I like them too. I don't see anything unpythonic about them. > That allows me > to put the parser setup right

Re: [Python-Dev] argparse ugliness

2010-03-08 Thread Ron Adam
Steven Bethard wrote: On Mon, Mar 8, 2010 at 7:40 AM, Steven Bethard wrote: On Sun, Mar 7, 2010 at 11:49 AM, Guido van Rossum wrote: On Sun, Mar 7, 2010 at 4:29 AM, Neal Becker wrote: Brian Curtin wrote: On Fri, Mar 5, 2010 at 12:51, Neal Becker wrote: I generally enjoy argparse, but

Re: [Python-Dev] argparse ugliness

2010-03-08 Thread David Stanek
On Mon, Mar 8, 2010 at 11:49 AM, Xavier Morel wrote: > On 8 Mar 2010, at 16:53 , David Stanek wrote: >> >> On Mon, Mar 8, 2010 at 10:40 AM, Steven Bethard >> wrote: >>> >>> In argparse, unlike optparse, actions are actually defined by objects >>> with a particular API, and the string is just a sh

Re: [Python-Dev] argparse ugliness

2010-03-08 Thread Xavier Morel
On 8 Mar 2010, at 16:53 , David Stanek wrote: > > On Mon, Mar 8, 2010 at 10:40 AM, Steven Bethard > wrote: >> >> 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_arg

Re: [Python-Dev] argparse ugliness

2010-03-08 Thread Neal Becker
On Monday 08 March 2010, David Stanek wrote: > On Mon, Mar 8, 2010 at 10:40 AM, Steven Bethard > > wrote: > > 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_arg

Re: [Python-Dev] argparse ugliness

2010-03-08 Thread David Stanek
On Mon, Mar 8, 2010 at 10:40 AM, Steven Bethard wrote: > > 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: >

Re: [Python-Dev] argparse ugliness

2010-03-08 Thread Steven Bethard
On Mon, Mar 8, 2010 at 7:40 AM, Steven Bethard wrote: > On Sun, Mar 7, 2010 at 11:49 AM, Guido van Rossum wrote: >> On Sun, Mar 7, 2010 at 4:29 AM, Neal Becker wrote: >>> Brian Curtin wrote: >>> On Fri, Mar 5, 2010 at 12:51, Neal Becker wrote: > I generally enjoy argparse, but one

Re: [Python-Dev] argparse ugliness

2010-03-08 Thread Steven Bethard
On Sun, Mar 7, 2010 at 11:49 AM, Guido van Rossum wrote: > On Sun, Mar 7, 2010 at 4:29 AM, Neal Becker wrote: >> Brian Curtin wrote: >> >>> On Fri, Mar 5, 2010 at 12:51, Neal Becker wrote: >>> I generally enjoy argparse, but one thing I find rather ugly and unpythonic.    par

Re: [Python-Dev] argparse ugliness

2010-03-08 Thread Mark Russell
On 7 Mar 2010, at 19:49, Guido van Rossum wrote: > How would you write the example instead then? Boolean flags are a common enough case that I'd be inclined to add a wrapper method, so you could just say: parser.add_bool_argument('--plot') As you can always fall back to the more general

Re: [Python-Dev] argparse ugliness

2010-03-07 Thread Guido van Rossum
On Sun, Mar 7, 2010 at 4:29 AM, Neal Becker wrote: > Brian Curtin wrote: > >> On Fri, Mar 5, 2010 at 12:51, Neal Becker wrote: >> >>> I generally enjoy argparse, but one thing I find rather >>> ugly and unpythonic. >>> >>>    parser.add_argument ('--plot', action='store_true') >>> >>> Specifying

Re: [Python-Dev] argparse ugliness

2010-03-07 Thread Neal Becker
Brian Curtin wrote: > On Fri, Mar 5, 2010 at 12:51, Neal Becker 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 el

Re: [Python-Dev] argparse ugliness

2010-03-07 Thread Georg Brandl
Am 06.03.2010 03:28, schrieb Antoine Pitrou: > Le Fri, 05 Mar 2010 13:51:15 -0500, > Neal Becker a écrit : >> I generally enjoy argparse, but one thing I find rather >> ugly and unpythonic. >> >> parser.add_argument ('--plot', action='store_true') > > I would argue that a string is actually

Re: [Python-Dev] argparse ugliness

2010-03-06 Thread Greg Ewing
Antoine Pitrou wrote: I would argue that a string is actually more Pythonic than integers or anonymous objects repurposed as magic constants. (I'm looking at things such as SEEK_SET and friends) Strings are certainly preferable to ints, one reason being that they display as something meaningfu

Re: [Python-Dev] argparse ugliness

2010-03-06 Thread Xavier Morel
I don't believe argparse's action specification scheme is bad either, but On 6 Mar 2010, at 13:50 , Nick Coghlan wrote: > > you wouldn't get the static name checking that is > the primary benefit of using named constants in less dynamic languages. There are quite a few tools which do handle stat

Re: [Python-Dev] argparse ugliness

2010-03-06 Thread Nick Coghlan
Neal Becker 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. It isn't ideal, but having to grab constants from the module isn't ideal e

Re: [Python-Dev] argparse ugliness

2010-03-05 Thread Antoine Pitrou
Le Fri, 05 Mar 2010 13:51:15 -0500, Neal Becker a écrit : > I generally enjoy argparse, but one thing I find rather > ugly and unpythonic. > > parser.add_argument ('--plot', action='store_true') I would argue that a string is actually more Pythonic than integers or anonymous objects repurpos

Re: [Python-Dev] argparse ugliness

2010-03-05 Thread Steven Bethard
On Fri, Mar 5, 2010 at 10:51 AM, Neal Becker 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. If it really bothers you, you can use:

Re: [Python-Dev] argparse ugliness

2010-03-05 Thread Brian Curtin
On Fri, Mar 5, 2010 at 12:51, Neal Becker 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

[Python-Dev] argparse ugliness

2010-03-05 Thread Neal Becker
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. ___ Python-Dev mailing list Python-Dev@python.org http://mail