Argparse“ArgumentError: argument -h/--help: conflicting option string(s): -h, --help”

前端 未结 2 1289
情歌与酒
情歌与酒 2021-02-05 00:29

Recently, I am learning argparse module, Argument error occurred below the code

import argparse
import sys


class ExecuteShell(object):
    def create(self, arg         


        
相关标签:
2条回答
  • 2021-02-05 00:47

    argparse adds --help and -h options by default. If you don't want to use the built-in help feature, you need to disable it with:

    parser = argparse.ArgumentParser(add_help=False)
    

    See the documentation

    0 讨论(0)
  • 2021-02-05 00:49

    The same error pop-ups in 2 other scenarios:

    1) Repeated code

    parser.add_argument('-h',
                            '--help',
                            action='store_true',
                            help=argparse.SUPPRESS)
    
    parser.add_argument('-h',
                            '--help',
                            action='store_true',
                            help=argparse.SUPPRESS)
    

    2) When you execute the code multiple times on the same kernel

    I'm leaving it just in case if someone had simillar problem.

    0 讨论(0)
提交回复
热议问题