An optparse question

fuzzylollipop jarrod.roberson at gmail.com
Fri Jul 21 15:48:54 EDT 2006


T wrote:
> I have a short program using optparse.OptionParser that prints out help
> message with -h flag:
>
> % myprog.py -h
> usage: myprog.py [options] input_file
>
> options:
>   -h, --help             show this help message and exit
>   -v, --verbose        print program's version number and exit
>   -o FILE               Output file
>
>
> My question is, is there a way to print a blank line (or any string)
> before "usage: myprog.py [options] input_file" ?  I tried using
> callbacks without success.  I think somehow I need to modify the
> behavior of optparse.OptionParser.print_usage() function?

you can make the usage line anything you want.

...
usage = 'This is a line before the usage line\nusage %prog [options]
input_file'
parser = OptionsParser(usage=usage)
parser.print_help()
...




More information about the Python-list mailing list