[Tutor] OptionParser

Wayne Werner waynejwerner at gmail.com
Mon Sep 19 21:05:57 CEST 2011


On Mon, Sep 19, 2011 at 1:22 PM, Mina Nozar <nozarm at triumf.ca> wrote:

> **
> I don't really understand what dest and action in the arguments to
> parser.add_option mean.
> Any help is appreciated.
>

Have you read the fine manual, specifically the sections here:
http://docs.python.org/library/optparse.html#optparse-standard-option-actions

and here:
http://docs.python.org/library/optparse.html#option-attributes

Additionaly, I'm not sure you copied your code correctly, because after a
copy and paste I get this:

$ python localtest.py
Traceback (most recent call last):
  File "localtest.py", line 5, in <module>
    parser.add_option("-cvs", dest="output", default=True, help="outputs the
csv file for plotting activites")
  File "/usr/lib/python2.6/optparse.py", line 1012, in add_option
    option = self.option_class(*args, **kwargs)
  File "/usr/lib/python2.6/optparse.py", line 566, in __init__
    self._set_opt_strings(opts)
  File "/usr/lib/python2.6/optparse.py", line 606, in _set_opt_strings
    self)
optparse.OptionError: invalid long option string '-cvs': must start with --,
followed by non-dash

and when I correct that:

$ python localtest.py -h

uwwerne at WWERNER /c
$

I get no output.

HTH,
Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110919/a107a762/attachment-0001.html>


More information about the Tutor mailing list