[Tutor] OptionParser

Prasad, Ramit ramit.prasad at jpmorgan.com
Tue Sep 20 23:27:15 CEST 2011


> from optparse import OptionParser
I am not sure what version of Python you are using but from 2.7+ optparse is deprercated. You may want to use that if you can. 

> I don't really understand what dest and action in the arguments to parser.add_option mean.  
Here is your usage:
>>> parser = OptionParser(usage="blahblahblah")
>>> parser.add_option("-f", "--file", dest="filename")
<Option at 0x8332eb8: -f/--file>
>>> (options, args) = parser.parse_args(['-f filename.csv']) # test in interpreter
>>> options.filename
' filename.csv' # Note the space before filename
>>> print options.filename
 filename.csv

See the documentation: http://docs.python.org/library/optparse.html 

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  


More information about the Tutor mailing list