Need help with OptionParser

hellt Dodin.Roman at gmail.com
Tue Mar 25 13:50:36 CET 2008


On 25 мар, 15:42, hellt <Dodin.Ro... at gmail.com> wrote:
> 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()



More information about the Python-list mailing list