Help with optionparse recipe
Stephen Boulet
stephen.no at spam.theboulets.net.please
Tue Jul 27 01:40:46 EDT 2004
I'm having trouble with the "optionparse" recipe in the cookbook:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278844
This does not give me the results I expected (namely the arguments on the
command line for each flag):
#!/usr/bin/env python
"""An example script invoking optionparse, my wrapper around optparse.
usage: %prog [options] args
-f, --file: file to attach
-s, --subject: email subject
-a, --address: email address
"""
import optionparse
opt, args = optionparse.parse(__doc__)
if not opt and not args:
optionparse.exit()
if opt.file:
print opt.file
if opt.subject:
print opt.subject
if opt.address:
print opt.address
Result:
$ python opttest.py -f "myfile.txt" -s "Here's the file" \
-a someone at there.net
True
True
True
What am I doing wrong here?
--
Stephen
If your desktop gets out of control easily,
you probably have too much stuff on it that
doesn't need to be there.
Donna Smallin, "Unclutter Your Home"
More information about the Python-list
mailing list