Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: optparse, allowing both --foo and foo=99?

Reply
Thread Tools

Re: optparse, allowing both --foo and foo=99?

 
 
Carl Banks
Guest
Posts: n/a
 
      10-16-2009
On Oct 15, 10:29*pm, Mark Harrison <(E-Mail Removed)> wrote:
> What's the magic to allow this? *If the value is not specified I
> would like to use the default value of 1.
>
> import optparse
> p=optparse.OptionParser()
> p.add_option("--debug")
>
> (opts, args) = p.parse_args(['--debug=22']); print opts
> (opts, args) = p.parse_args(['--debug']); * *print opts


Unless you need to avoid third-party dependencies, install argparse
(http://code.google.com/p/argparse) and don't give optparse another
look.

With argparse (which has a similar but not compatible api) you can do
it like this:

p=optparse.ArgumentParser()
p.add_argument("--debug",nargs='?')


Carl Banks
 
Reply With Quote
 
 
 
 
Jean-Michel Pichavant
Guest
Posts: n/a
 
      10-16-2009
Carl Banks wrote:
> On Oct 15, 10:29 pm, Mark Harrison <(E-Mail Removed)> wrote:
>
>> What's the magic to allow this? If the value is not specified I
>> would like to use the default value of 1.
>>
>> import optparse
>> p=optparse.OptionParser()
>> p.add_option("--debug")
>>
>> (opts, args) = p.parse_args(['--debug=22']); print opts
>> (opts, args) = p.parse_args(['--debug']); print opts
>>

>
> Unless you need to avoid third-party dependencies, install argparse
> (http://code.google.com/p/argparse) and don't give optparse another
> look.
>
> With argparse (which has a similar but not compatible api) you can do
> it like this:
>
> p=optparse.ArgumentParser()
> p.add_argument("--debug",nargs='?')
>
>
> Carl Banks
>

What is the problem with optparse ? AFAIK, it is pretty much satisfying.

JM
 
Reply With Quote
 
 
 
 
Jean-Michel Pichavant
Guest
Posts: n/a
 
      10-16-2009
Jean-Michel Pichavant wrote:
> Carl Banks wrote:
>> On Oct 15, 10:29 pm, Mark Harrison <(E-Mail Removed)> wrote:
>>
>>> What's the magic to allow this? If the value is not specified I
>>> would like to use the default value of 1.
>>>
>>> import optparse
>>> p=optparse.OptionParser()
>>> p.add_option("--debug")
>>>
>>> (opts, args) = p.parse_args(['--debug=22']); print opts
>>> (opts, args) = p.parse_args(['--debug']); print opts
>>>

>>
>> Unless you need to avoid third-party dependencies, install argparse
>> (http://code.google.com/p/argparse) and don't give optparse another
>> look.
>>
>> With argparse (which has a similar but not compatible api) you can do
>> it like this:
>>
>> p=optparse.ArgumentParser()
>> p.add_argument("--debug",nargs='?')
>>
>>
>> Carl Banks
>>

> What is the problem with optparse ? AFAIK, it is pretty much satisfying.
>
> JM
>

Please, kindly ignore my question
(http://argparse.googlecode.com/svn/t...-optparse.html)
JM
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
compilation error: file exists in both in both 'c:\WINNT\Microsoft.NET\Framework\v2.0.50727 ABCL ASP .Net 0 05-29-2008 04:59 PM
2 computers, both online, both invisible to each other ? b Computer Support 9 04-21-2006 04:06 AM
Pix and vlan allowing traffic ntst Cisco 1 03-23-2006 03:10 AM
Pix and vlan allowing traffic ntst Cisco 0 03-22-2006 11:13 PM
Help with Pix 515E firewall and allowing Outbound VPNs Kilgore Troute Cisco 1 08-26-2004 08:41 PM



Advertisments