Вопрос по python – Отключить сокращение в argparse

12

Error: User Rate Limit Exceeded

Error: User Rate Limit ExceededError: User Rate Limit Exceeded.

Является ли это возможным?

Example:

import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--send', action='store_true')
parser.parse_args(['--se']) # returns Namespace(send=True)

Error: User Rate Limit Exceeded

UPDATE:

Error: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit Exceeded

Ваш Ответ

4   ответа
6

parser = argparse.ArgumentParser(allow_abbrev=False)

.

Error: User Rate Limit Exceeded jens
Error: User Rate Limit Exceeded
3

--dog

p = argparse.ArgumentParser()
p.add_argument('--dog')
p.add_argument('--dox', help=argparse.SUPPRESS, metavar='IGNORE')

--dox--d--doparse_args

help=...metavar='IGNORE'

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
4

def _get_option_tuples(self, option_string):
    ...
    if option_string.startswith(option_prefix):
    ...

startswith==.

argparse.ArgumentParser_get_option_tuples(self, option_string)option_string.startswith(option_prefix)option_string == option_prefix

>>> parser = my_argparse.MyArgparse
>>> parser = my_argparse.MyArgparse()
>>> parser.add_argument('--send', action='store_true')
_StoreTrueAction(option_strings=['--send'], dest='send', nargs=0, const=True, default=False, type=None, choices=None, help=None, metavar=None)
>>> parser.parse_args(['--se'])
usage: [-h] [--send]
: error: unrecognized arguments: --se

A word of caution

_get_option_tuples_

Error: User Rate Limit Exceeded jens
4

    # allow one or more arguments
    elif nargs == ONE_OR_MORE:
        nargs_pattern = '(-*A[A-]*)'

    # if this is an optional action, -- is not allowed
    if action.option_strings:
        nargs_pattern = nargs_pattern.replace('-*', '')
        nargs_pattern = nargs_pattern.replace('-', '')
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded

Похожие вопросы