optparser: how to register callback to display binary's help

hiral hiralsmaillist at gmail.com
Wed Oct 13 07:34:38 EDT 2010


Hi,

I want to display help message of python script and then display help
message from the binary file (which also supports -h option):

Assumptions:
1) 'mybinary' - is linux executable file which supports '-h' and on '-
h' option it displays the help message
2) myscript.py - when passing '-h' option want to call 'mybinary -h'
and display help messages of both script and binary.

Code:
====
from optparse import OptionParser
[...]
parser = OptionParser()
parser.add_option("-e", "--execute", dest="file",
                  help="Execute binary", metavar="FILE")
(options, args) = parser.parse_args()
if options.file:
    subprocess.call(options.file)


Requirement:
$ python myscript.py -h
<currently it prints the help message with '-e' and '-h' help message>
<becides I want to display help message of 'mybinary'>

Thank you in advance.
-Hiral



More information about the Python-list mailing list