Merge pull request #889 from PaddlePaddle/parse_file

argparse load conf from file
pull/891/head
Hui Zhang 3 years ago committed by GitHub
commit 3c32a292e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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)

Loading…
Cancel
Save