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

标签 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')

运行脚本时出现错误信息:

 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/

相关文章:

python - 在 openshift 上运行无限循环的简单 python 应用程序

python - 如何均匀地间隔数据框中的日期数据?

linux - 是否可以在 Linux 中编译带有 MSB 标志的 ELF 文件

linux - 静态 Sprite 图像设置的段 %fs 在哪里?

linux - 为什么我必须使用ld链接我的二进制文件

gcc - 使用objcopy将二进制嵌入到elf中可能会导致对齐问题?

python - ImportError:使用 manage.py 时没有名为 django.core.management 的模块

python - 如何查找落在每一行的时间段内的行数,同时满足其他列中的条件?

Python:菜谱程序

linux - 如何 Hook 特定共享 ELF 库的函数?