當前位置: 首頁>>代碼示例>>Python>>正文


Python argparse._CountAction方法代碼示例

本文整理匯總了Python中argparse._CountAction方法的典型用法代碼示例。如果您正苦於以下問題:Python argparse._CountAction方法的具體用法?Python argparse._CountAction怎麽用?Python argparse._CountAction使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在argparse的用法示例。


在下文中一共展示了argparse._CountAction方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: run_test

# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import _CountAction [as 別名]
def run_test(**options):
    """Runs a molotov test.
    """
    parser = _parser()
    fields = {}
    cli = []
    for action in parser._actions:
        if action.dest in ("help", "scenario"):
            continue
        op_str = action.option_strings[0]
        fields[action.dest] = op_str, action.const, type(action)

    for key, value in options.items():
        if key in fields:
            opt, const, type_ = fields[key]
            is_count = type_ is argparse._CountAction
            if const or is_count:
                if is_count:
                    cli += [opt] * value
                else:
                    cli.append(opt)
            else:
                cli.append(opt)
                cli.append(str(value))

    cli.append(options.pop("scenario", "loadtest.py"))
    args = parser.parse_args(args=cli)
    print("Running: molotov %s" % " ".join(cli))
    return run(args) 
開發者ID:loads,項目名稱:molotov,代碼行數:31,代碼來源:slave.py

示例2: add_dynamic_attr

# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import _CountAction [as 別名]
def add_dynamic_attr(cls, klass):
    parser = klass.create_parser()
    import argparse
    for action in parser._actions:
        if isinstance(action, argparse._HelpAction):
            continue

        if isinstance(action, (argparse._StoreTrueAction, argparse._StoreTrueAction)):
            cls.locals[action.dest] = [bool]
        elif isinstance(action, argparse._CountAction):
            cls.locals[action.dest] = [int]
        elif isinstance(action, (argparse._AppendAction, argparse._AppendConstAction)):
            cls.locals[action.dest] = [list]
        else:
            cls.locals[action.dest] = [action.type] 
開發者ID:ansible,項目名稱:ansibullbot,代碼行數:17,代碼來源:triagers.py

示例3: convert_setting_to_command_line_arg

# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import _CountAction [as 別名]
def convert_setting_to_command_line_arg(self, action, key, value):
        args = []
        if action is None:
            command_line_key = \
                self.get_command_line_key_for_unknown_config_file_setting(key)
        else:
            command_line_key = action.option_strings[-1]

        if isinstance(action, argparse._StoreTrueAction):
            if value is True:
                args.append(command_line_key)
        elif isinstance(action, argparse._StoreFalseAction):
            if value is False:
                args.append(command_line_key)
        elif isinstance(action, argparse._StoreConstAction):
            if value == action.const:
                args.append(command_line_key)
        elif isinstance(action, argparse._CountAction):
            for _ in range(value):
                args.append(command_line_key)
        elif action is not None and value == action.default:
            pass
        elif isinstance(value, list):
            args.append(command_line_key)
            args.extend([str(e) for e in value])
        else:
            args.append(command_line_key)
            args.append(str(value))
        return args 
開發者ID:stanfordnlp,項目名稱:stanza-old,代碼行數:31,代碼來源:config.py


注:本文中的argparse._CountAction方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。