468,736 Members | 2,113 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,736 developers. It's quick & easy.

Need help with OptionParser

today i've decided to use optionparser instead of GetOpt

and unfortunately i've got an error which i cant handle

my pice of code:

from optparse import OptionParser

def main():
usage = "usage: %prog [options]"
parser = OptionParser(usage)
parser.add_option("-f", "--file", dest="filename",
help="executable filename",
metavar="FILE")
parser.add_option("-b", "--bighosts",
action="store_true", dest="bighosts", default=False,
help="with big hosts [default: %default]")
(options, args) = parser.parse_args()
if not options.bighosts:
print parser.print_usage()
if __name__=="__main__":
main()
if i run test3.py without any arguments, i wait for generated help,
but i see the following

Usage: test3.py [options]

None

why None? Where are all of my options
Mar 25 '08 #1
1 2416
On 25 อมา, 15:42, hellt <Dodin.Ro...@gmail.comwrote:
today i've decided to use optionparser instead of GetOpt

and unfortunately i've got an error which i cant handle

my pice of code:

from optparse import OptionParser

def main():
usage = "usage: %prog [options]"
parser = OptionParser(usage)
parser.add_option("-f", "--file", dest="filename",
help="executable filename",
metavar="FILE")
parser.add_option("-b", "--bighosts",
action="store_true", dest="bighosts", default=False,
help="with big hosts [default: %default]")
(options, args) = parser.parse_args()
if not options.bighosts:
print parser.print_usage()

if __name__=="__main__":
main()

if i run test3.py without any arguments, i wait for generated help,
but i see the following

Usage: test3.py [options]

None

why None? Where are all of my options
=) my bad
unnecessary print in
print parser.print_usage()
and print_help() instead print_usage()
Mar 25 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Bart Nessux | last post: by
2 posts views Thread by Florian Lindner | last post: by
7 posts views Thread by R. Bernstein | last post: by
reply views Thread by U S Contractors Offering Service A Non-profit | last post: by
23 posts views Thread by Thorsten Kampe | last post: by
20 posts views Thread by Casey | last post: by
reply views Thread by lgwe | last post: by
5 posts views Thread by john.m.roach | last post: by
4 posts views Thread by tekion | last post: by
xarzu
2 posts views Thread by xarzu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.