-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharg_tools.py
41 lines (34 loc) · 1021 Bytes
/
arg_tools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
def get_argparse(description, **parsers):
"""
获取命令行参数
:param description: 描述
:param parsers: 调用方式为 --参数名=参数值
参数列表, 格式如下
参数名={
"type": str,
"default": "train",
"choices": ["train", "save", "infer"],
"help": "model: train, save, infer",
"required": False,
}
:return:
"""
parser = argparse.ArgumentParser(description=description)
for name, value in parsers.items():
parser.add_argument(f"--{name}", **value)
return parser
if __name__ == '__main__':
args = get_argparse(
description="cruise_cnn",
model={
"type": str,
"default": "train",
"choices": ["train", "save", "infer"],
"help": "model: train, save, infer",
"required": False,
}
).parse_args()
print(args.model)