我有以下选择
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')
运行脚本时出现错误信息:
optparse.OptionConflictError: option -h/--file-header: conflicting option string(s): -h
我知道通常-h 是用来显示帮助的。但是我正在尝试为一些特殊的 elf 文件编写一个 ELF 文件读取器,因此我想使用与 readelf
相同的命令。并且 readelf 使用 -h 来打印标题信息。
是否有可能覆盖选项解析器中的 -h 选项或者是否已修复?
最佳答案
创建解析器时,传递 add_help_option=False
。然后你就可以自己定义了:
parser = OptionParser(add_help_option=False)
关于Python 选项解析器覆盖 '-h',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33669665/