Re: argparse - option with optional value

2012-05-18 Thread Ben Finney
Ben Finney writes: > Miki Tebeka writes: > > The way I'm doing it currently is: > > ... > > no_edit = 'no-edit' > > parser.add_argument('-e', '--edit', help='open editor on log', > > nargs='?', > > default=no_edit) > > There is a built-in “no value specified”

Re: argparse - option with optional value

2012-05-18 Thread Miki Tebeka
> There is a built-in “no value specified” value in Python: the None > singleton. The ‘argparse’ library uses this for the argument default > already, so you don't need to fuss with your own special handling > http://docs.python.org/library/argparse.html#default>. The problem with this approach is

Re: argparse - option with optional value

2012-05-17 Thread John O'Hagan
On Thu, 17 May 2012 14:26:50 -0700 (PDT) Miki Tebeka wrote: > Greetings, > > I'd like to have an --edit option in my program. That if not specified will > not open editor. If specified without value will open default editor > ($EDITOR) and if specified with value, assume this value is the editor

Re: argparse - option with optional value

2012-05-17 Thread Ben Finney
Miki Tebeka writes: > I'd like to have an --edit option in my program. That if not specified > will not open editor. If specified without value will open default > editor ($EDITOR) and if specified with value, assume this value is the > editor program to run. So, two rather separate tasks: handl

argparse - option with optional value

2012-05-17 Thread Miki Tebeka
Greetings, I'd like to have an --edit option in my program. That if not specified will not open editor. If specified without value will open default editor ($EDITOR) and if specified with value, assume this value is the editor program to run. The way I'm doing it currently is: ... no_ed