[Tutor] OptionParser

Mina Nozar nozarm at triumf.ca
Mon Sep 19 20:22:30 CEST 2011


Hello,

I am trying to use OptionParser (my first time) to set a variable (cvs_output).  i.e. if --csv is given in the list of 
options, then cvs_output = True.
Then I check,
if cvs_output == True:
[...]


I have the following so far but something is missing.
from optparse import OptionParser
usage = "usage: %prog [options]"
parser = OptionParser(usage=usage)
parser.add_option("-cvs", dest="output", default=True, help="outputs the csv file for plotting activites")


python dUCx_ActivityPlots.py

python dUCx_ActivityPlots.2.py -h
Usage: dUCx_ActivityPlots.2.py [options]

Options:
   -h, --help         show this help message and exit
   --cvs=OUTPUT_FLAG  outputs the csv file for plotting activities


I don't really understand what dest and action in the arguments to parser.add_option mean.
Any help is appreciated.
Mina
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110919/3c570d04/attachment.html>


More information about the Tutor mailing list