Skip to content

Python:optparse

Remove help option

기본 HTLP 옵션을 제거하고 싶다면 아래와 같이 사용하면 된다.

oparser = OptionParser(add_help_option=False, ...)

Example

from optparse import OptionParser

OPTION_PARSER = OptionParser()
OPTION_PARSER.add_option('--config'
    , dest='config_path', metavar='PATH', default='config.xml'
    , help='Set the configure file path.')
OPTION_PARSER.add_option('--generate-config'
    , dest='generate_config', metavar='PATH'
    , help='Generate configure xml file.')
OPTION_PARSER.add_option('--print-debug'
    , dest='print_debug', action='store_true', default=False
    , help='Print debugging output.')
OPTION_PARSER.add_option('--upload'
    , dest='upload_path', metavar='PATH'
    , help='Upload project or archive.')
OPTION_PARSER.add_option('--remote-list'
    , dest='remote_list', action='store_true', default=False
    , help='Print remote file list.')
(OPTIONS, ARGS) = OPTION_PARSER.parse_args()

if __name__ == '__main__':
    argv = sys.argv
    if len(argv) <= 1:
        OPTION_PARSER.print_help()

    if OPTIONS.generate_config:
        pass

See also

Favorite site