Optparse buggy?

F

Fulvio

Hello,

I'm on python3.2, trying some experiment with OptionParser but no success
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.
 
I

Ian Kelly

Hello,

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

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.

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
 
T

Terry Reedy

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."
 
F

Fulvio

Terry said:
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?
 
R

Roy Smith

Terry Reedy said:
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).
 
C

Carl Banks

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).

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 argparseinstead 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,273
Latest member
DamonShoem

Latest Threads

Top