Optparse buggy?

Ian Kelly ian.g.kelly at gmail.com
Thu Sep 1 23:24:33 CEST 2011

On Thu, Sep 1, 2011 at 3:12 PM, Fulvio <false at pp.jaring.my> wrote:
> 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.

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


More information about the Python-list mailing list