Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Optparse buggy?

82 views
Skip to first unread message

Fulvio

unread,
Sep 1, 2011, 5:12:44 PM9/1/11
to
Hello,

I'm on python3.2, trying some experiment with OptionParser but no success

>>> from optparse import OptionParser as parser
>>> parser.add_option('-n','--new', dest='new')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.2/optparse.py", line 1001, in add_option
option = self.option_class(*args, **kwargs)
AttributeError: 'str' object has no attribute 'option_class'
>>>

Any futher item in the option won't make any better.
--
Archlinux on $(uname -a) :P

Ian Kelly

unread,
Sep 1, 2011, 5:24:33 PM9/1/11
to fa...@pp.jaring.my, pytho...@python.org

You're trying to call the method from the OptionParser class -- you
need to instantiate it first.

from optparse import OptionParser
parser = OptionParser()


parser.add_option('-n', '--new', dest='new')

...

Cheers,
Ian

Terry Reedy

unread,
Sep 1, 2011, 5:51:32 PM9/1/11
to pytho...@python.org
On 9/1/2011 5:12 PM, Fulvio wrote:

> I'm on python3.2, trying some experiment with OptionParser but no success

Do note "The optparse module is deprecated and will not be developed
further; development will continue with the argparse module."

--
Terry Jan Reedy

Fulvio

unread,
Sep 1, 2011, 10:11:55 PM9/1/11
to
Terry Reedy wrote:

> Do note "The optparse module is deprecated and will not be developed
> further; development will continue with the argparse module."

Then,do you propose me to opt to argparse?

--
Archlinux on $(uname -a) :P

F

Roy Smith

unread,
Sep 1, 2011, 10:16:13 PM9/1/11
to
In article <mailman.666.13149139...@python.org>,
Terry Reedy <tjr...@udel.edu> wrote:

> Do note "The optparse module is deprecated and will not be developed
> further; development will continue with the argparse module."

One of the unfortunate things about optparse and argparse is the names.
I can never remember which is the new one and which is the old one. It
would have been a lot simpler if the new one had been named optparse2
(in the style of unittest2 and urllib2).

Ben Finney

unread,
Sep 1, 2011, 10:18:19 PM9/1/11
to
Fulvio <fa...@pp.jaring.my> writes:

> Terry Reedy wrote:
>
> > Do note "The optparse module is deprecated and will not be developed
> > further; development will continue with the argparse module."
>
> Then,do you propose me to opt to argparse?

Without argument, yes; though for now it is opt-in.

--
\ “We are no more free to believe whatever we want about God than |
`\ we are free to adopt unjustified beliefs about science or |
_o__) history […].” —Sam Harris, _The End of Faith_, 2004 |
Ben Finney

Carl Banks

unread,
Sep 2, 2011, 1:42:08 AM9/2/11
to

It's easy: "opt"parse parses only "opt"ions (-d and the like), whereas "arg"parse parses all "arg"uments. argparse is the more recent version since it does more. optparse2 would have been a bad name for something that parses more than options.

(In fact, although I have some minor philosophical disagreements with optparse's design decisions, the main reason I always recommended using argparse instead was that optparse didn't handle positional arguments. optparse has all these spiffy features with type checking and defaults, but it never occurred to the optparse developers that this stuff would be useful for positional arugments, too. They just dropped the ball there.)


Carl Banks

0 new messages