【问题标题】:Python option parser overwrite '-h'Python 选项解析器覆盖“-h”
【发布时间】:2016-02-13 16:08:19
【问题描述】:

我有以下选择

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 选项或者是否已修复?

【问题讨论】:

    标签: python elf


    【解决方案1】:

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

    parser =  OptionParser(add_help_option=False)
    

    【讨论】:

      猜你喜欢
      • 2020-09-03
      • 2016-04-05
      • 1970-01-01
      • 2011-08-29
      • 2018-04-04
      • 2013-12-21
      • 1970-01-01
      • 2013-10-03
      • 1970-01-01
      相关资源
      最近更新 更多