Need help with OptionParser

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • hellt

    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(us age)
    parser.add_opti on("-f", "--file", dest="filename" ,
    help="executabl e filename",
    metavar="FILE")
    parser.add_opti on("-b", "--bighosts",
    action="store_t rue", dest="bighosts" , default=False,
    help="with big hosts [default: %default]")
    (options, args) = parser.parse_ar gs()
    if not options.bighost s:
    print parser.print_us age()


    if __name__=="__ma in__":
    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
  • hellt

    #2
    Re: Need help with OptionParser

    On 25 ÍÁÒ, 15:42, hellt <Dodin.Ro...@gm ail.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(us age)
    parser.add_opti on("-f", "--file", dest="filename" ,
    help="executabl e filename",
    metavar="FILE")
    parser.add_opti on("-b", "--bighosts",
    action="store_t rue", dest="bighosts" , default=False,
    help="with big hosts [default: %default]")
    (options, args) = parser.parse_ar gs()
    if not options.bighost s:
    print parser.print_us age()
    >
    if __name__=="__ma in__":
    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_us age()
    and print_help() instead print_usage()

    Comment

    Working...