本文整理汇总了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)
示例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
示例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
示例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)
示例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)
示例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)
示例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)
示例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)
示例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')
示例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)
示例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)
示例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")
示例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
示例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)
示例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)