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


Python ArgumentParser.add_argument方法代碼示例

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


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

示例1: require_output_table

# 需要導入模塊: from argparse import ArgumentParser [as 別名]
# 或者: from argparse.ArgumentParser import add_argument [as 別名]
def require_output_table(
        self, partition_spec_spec, metadata_fn=None,
        mode='overwrite',
    ):
        @self._post_process_transform.append
        def post(df: DataFrame, kwargs: Dict):
            mt.write_partition(
                df, kwargs['output_table'], kwargs['output_path'],
                self._resolve_partition_spec(kwargs, partition_spec_spec),
                mode=mode)
            if metadata_fn is not None:
                spark = df.sql_ctx.sparkSession
                metadata = metadata_fn(spark.read.parquet(kwargs['output_path']))
                write_metadata(kwargs['output_path'], metadata)

        self.add_argument('--output-table', required=True)
        self.add_argument('--output-path', required=True) 
開發者ID:wikimedia,項目名稱:search-MjoLniR,代碼行數:19,代碼來源:helpers.py

示例2: _pre_argument_parsing

# 需要導入模塊: from argparse import ArgumentParser [as 別名]
# 或者: from argparse.ArgumentParser import add_argument [as 別名]
def _pre_argument_parsing(self):
        """
        Called on every controller just before arguments are parsed.
        Provides an alternative means of adding arguments to the controller,
        giving more control than using ``Meta.arguments``.

        .. code-block:: python

            class Base(ArgparseController):
                class Meta:
                    label = 'base'

                def _pre_argument_parsing(self):
                    p = self._parser
                    p.add_argument('-f', '--foo',
                                   help='my foo option',
                                   dest='foo')

                def _post_argument_parsing(self):
                    if self.app.pargs.foo:
                        print('Got Foo Option Before Controller Dispatch')

        """
        pass 
開發者ID:QData,項目名稱:deepWordBug,代碼行數:26,代碼來源:ext_argparse.py

示例3: parser

# 需要導入模塊: from argparse import ArgumentParser [as 別名]
# 或者: from argparse.ArgumentParser import add_argument [as 別名]
def parser(self) -> ArgumentParser:
        """Returns an ``ArgumentParser`` for this option set.

        Generally, you won't use this directly. Instead, use
        :func:`parse_args`.
        """
        parser = argparse.ArgumentParser(*self.parser_args, **self.parser_kwargs)

        groups = {
            name: parser.add_argument_group(*option_group.args, **option_group.kwargs)
            for name, option_group in self.groups.items()
        }

        for option in self.options.values():
            if option.hidden:
                continue

            argument = groups[option.group.name].add_argument(
                *option.flags, help=option.help, default=option.default, **option.kwargs
            )
            if getattr(option, "completer"):
                setattr(argument, "completer", option.completer)

        return parser 
開發者ID:theacodes,項目名稱:nox,代碼行數:26,代碼來源:_option_set.py

示例4: __init__

# 需要導入模塊: from argparse import ArgumentParser [as 別名]
# 或者: from argparse.ArgumentParser import add_argument [as 別名]
def __init__(self, name: str, transformer: Callable, parser: ArgumentParser):
        self.name = name
        self.transformer = transformer
        self.parser = parser
        self._post_process_args = CallQueue()
        self._post_process_transform = CallQueue()
        self._cleanup = CallQueue()
        # Default args for all scripts
        self.add_argument('--date', required=True) 
開發者ID:wikimedia,項目名稱:search-MjoLniR,代碼行數:11,代碼來源:helpers.py

示例5: add_argument

# 需要導入模塊: from argparse import ArgumentParser [as 別名]
# 或者: from argparse.ArgumentParser import add_argument [as 別名]
def add_argument(self, *args, **kwargs):
        return self.parser.add_argument(*args, **kwargs) 
開發者ID:wikimedia,項目名稱:search-MjoLniR,代碼行數:4,代碼來源:helpers.py

示例6: require_kafka_arguments

# 需要導入模塊: from argparse import ArgumentParser [as 別名]
# 或者: from argparse.ArgumentParser import add_argument [as 別名]
def require_kafka_arguments(self):
        self.add_argument('--brokers', required=True)
        self.add_argument('--topic-request', required=True)
        self.add_argument('--topic-response', required=True) 
開發者ID:wikimedia,項目名稱:search-MjoLniR,代碼行數:6,代碼來源:helpers.py

示例7: require_daily_input_table

# 需要導入模塊: from argparse import ArgumentParser [as 別名]
# 或者: from argparse.ArgumentParser import add_argument [as 別名]
def require_daily_input_table(self):
        @self._post_process_args.append
        def post(spark: SparkSession, kwargs: Dict) -> None:
            kwargs['df_in'] = spark.read.table(kwargs['input_table']) \
                .drop('year', 'month', 'day')

        self.add_argument('--input-table', required=True) 
開發者ID:wikimedia,項目名稱:search-MjoLniR,代碼行數:9,代碼來源:helpers.py

示例8: require_query_clicks_partition

# 需要導入模塊: from argparse import ArgumentParser [as 別名]
# 或者: from argparse.ArgumentParser import add_argument [as 別名]
def require_query_clicks_partition(self):
        @self._post_process_args.append
        def post(spark: SparkSession, kwargs: Dict) -> None:
            kwargs['query_clicks'] = HivePartition(
                spark, kwargs['clicks_table'], {
                    'date': kwargs['date'],
                })

        self.add_argument('--clicks-table', required=True) 
開發者ID:wikimedia,項目名稱:search-MjoLniR,代碼行數:11,代碼來源:helpers.py

示例9: require_labeled_query_page_partition

# 需要導入模塊: from argparse import ArgumentParser [as 別名]
# 或者: from argparse.ArgumentParser import add_argument [as 別名]
def require_labeled_query_page_partition(self):
        @self._post_process_args.append
        def post(spark: SparkSession, kwargs: Dict) -> None:
            kwargs['labeled_query_page'] = HivePartition(
                spark, kwargs['labels_table'], {
                    'date': kwargs['date'],
                    'algorithm': kwargs['labeling_algorithm'],
                })

        self.add_argument('--labels-table', required=True)
        self.add_argument('--labeling-algorithm') 
開發者ID:wikimedia,項目名稱:search-MjoLniR,代碼行數:13,代碼來源:helpers.py

示例10: require_feature_vectors_partition

# 需要導入模塊: from argparse import ArgumentParser [as 別名]
# 或者: from argparse.ArgumentParser import add_argument [as 別名]
def require_feature_vectors_partition(self):
        @self._post_process_args.append
        def post(spark: SparkSession, kwargs: Dict) -> None:
            kwargs['feature_vectors'] = HivePartition(
                spark, kwargs['feature_vectors_table'], {
                    'date': kwargs['date'],
                    'feature_set': kwargs['feature_set']
                }, direct_parquet_read=True)

        self.add_argument('--feature-vectors-table', required=True)
        self.add_argument('--feature-set', required=True) 
開發者ID:wikimedia,項目名稱:search-MjoLniR,代碼行數:13,代碼來源:helpers.py

示例11: require_training_files_partition

# 需要導入模塊: from argparse import ArgumentParser [as 別名]
# 或者: from argparse.ArgumentParser import add_argument [as 別名]
def require_training_files_partition(self):
        @self._post_process_args.append
        def post(spark: SparkSession, kwargs: Dict) -> None:
            kwargs['training_files'] = read_metadata(
                kwargs['training_files_path'])

        self.add_argument('--training-files-path', required=True) 
開發者ID:wikimedia,項目名稱:search-MjoLniR,代碼行數:9,代碼來源:helpers.py

示例12: require_model_parameters_partition

# 需要導入模塊: from argparse import ArgumentParser [as 別名]
# 或者: from argparse.ArgumentParser import add_argument [as 別名]
def require_model_parameters_partition(self, only_table=False):
        self.add_argument('--model-parameters-table', required=True)
        if not only_table:
            raise NotImplementedError("TODO") 
開發者ID:wikimedia,項目名稱:search-MjoLniR,代碼行數:6,代碼來源:helpers.py

示例13: add_argument

# 需要導入模塊: from argparse import ArgumentParser [as 別名]
# 或者: from argparse.ArgumentParser import add_argument [as 別名]
def add_argument(self, *args, **kw):
        """
        Add an argument to the parser.  Arguments and keyword arguments are
        passed directly to ``ArgumentParser.add_argument()``.
        See the :py:class:`argparse.ArgumentParser` documentation for help.
        """
        super(ArgparseArgumentHandler, self).add_argument(*args, **kw)


# FIXME: Backward compat name, will remove in Cement 3.x 
開發者ID:QData,項目名稱:deepWordBug,代碼行數:12,代碼來源:ext_argparse.py

示例14: _process_arguments

# 需要導入模塊: from argparse import ArgumentParser [as 別名]
# 或者: from argparse.ArgumentParser import add_argument [as 別名]
def _process_arguments(self, controller):
        label = controller._meta.label

        LOG.debug("processing arguments for '%s' " % label +
                  "controller namespace")

        parser = self._get_parser_by_controller(controller)
        arguments = controller._collect_arguments()
        for arg, kw in arguments:
            LOG.debug('adding argument (args=%s, kwargs=%s)' % (arg, kw))
            parser.add_argument(*arg, **kw) 
開發者ID:QData,項目名稱:deepWordBug,代碼行數:13,代碼來源:ext_argparse.py

示例15: _process_commands

# 需要導入模塊: from argparse import ArgumentParser [as 別名]
# 或者: from argparse.ArgumentParser import add_argument [as 別名]
def _process_commands(self, controller):
        label = controller._meta.label
        LOG.debug("processing commands for '%s' " % label +
                  "controller namespace")
        parser = self._get_parser_by_controller(controller)

        commands = controller._collect_commands()
        for command in commands:
            kwargs = self._get_command_parser_options(command)

            func_name = command['func_name']
            LOG.debug("adding command '%s' " % command['label'] +
                      "(controller=%s, func=%s)" %
                      (controller._meta.label, func_name))

            cmd_parent = self._get_parser_parent_by_controller(controller)
            command_parser = cmd_parent.add_parser(command['label'], **kwargs)

            # add an invisible dispatch option so we can figure out what to
            # call later in self._dispatch
            default_contr_func = "%s.%s" % (command['controller']._meta.label,
                                            command['func_name'])
            command_parser.add_argument(self._dispatch_option,
                                        action='store',
                                        default=default_contr_func,
                                        help=SUPPRESS,
                                        dest='__dispatch__',
                                        )

            # add additional arguments to the sub-command namespace
            LOG.debug("processing arguments for '%s' " % command['label'] +
                      "command namespace")
            for arg, kw in command['arguments']:
                LOG.debug('adding argument (args=%s, kwargs=%s)' %
                          (arg, kw))
                command_parser.add_argument(*arg, **kw) 
開發者ID:QData,項目名稱:deepWordBug,代碼行數:38,代碼來源:ext_argparse.py


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