我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用argparse._CountAction()。
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