By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,965 Members | 1,450 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,965 IT Pros & Developers. It's quick & easy.

Need help with OptionParser

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.