Python选项解析器覆盖'-h'

Rol*_*ssi 4 python elf

我有以下选择

parser = OptionParser()
parser.add_option('-a', '--all', action='store_true', dest='all', help='writes all header information')
parser.add_option('-h', '--file-header', action='store_true', dest='head',  help='prints the elf file header information')
parser.add_option('-l', '--program-header', action='store_true', dest='prog',  help='prints the program header')
parser.add_option('-S', '--section-header', action='store_true', dest='sec',  help='prints the section header')
Run Code Online (Sandbox Code Playgroud)

运行脚本时,我收到错误消息:

 optparse.OptionConflictError: option -h/--file-header: conflicting option string(s): -h
Run Code Online (Sandbox Code Playgroud)

我知道通常-h是保留显示帮助.但我正在尝试为一些特殊的精灵文件编写一个ELF文件阅读器,因此我想使用相同的命令readelf.并且readelf使用-h来打印标题信息.

是否有可能在选项解析器中覆盖-h选项或者是否已修复?

mic*_*ael 8

在创建解析器时,传递add_help_option=False.然后你就可以自己定义它了:

parser =  OptionParser(add_help_option=False)
Run Code Online (Sandbox Code Playgroud)