未验证 提交 3c32a292 编写于 作者: H Hui Zhang 提交者: GitHub

Merge pull request #889 from PaddlePaddle/parse_file

argparse load conf from file
......@@ -28,6 +28,13 @@ class ExtendAction(argparse.Action):
setattr(namespace, self.dest, items)
class LoadFromFile(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
with values as f:
# parse arguments in the file and store them in the target namespace
parser.parse_args(f.read().split(), namespace)
def default_argument_parser():
r"""A simple yet genral argument parser for experiments with parakeet.
......@@ -57,6 +64,8 @@ def default_argument_parser():
"""
parser = argparse.ArgumentParser()
parser.register('action', 'extend', ExtendAction)
parser.add_argument(
'--conf', type=open, action=LoadFromFile, help="config file.")
train_group = parser.add_argument_group(
title='Train Options', description=None)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册