"""
主要学习内容
1. type default help action choice dest
2. required 为True的时候必须要初始化
3. nargs课代表List
4.流程
import argparse
parser = argparse.ArgumentParser(description='Train network')
arser.add_argument()
args1 = parser.parse_args("--epochs 120".split())
"""
import argparse
import jsonparser = argparse.ArgumentParser(description='Train network')
print(parser)
parser.add_argument("-batch_size",type =int, default=64,help="set batch size")
parser.add_argument("-thresh1",type =float, default=0.9,help="set thresh")
parser.add_argument("-use",type =bool, default=False,help="is use")
parser.add_argument("--image_type",choices=['R','G','B'],default='B', help ="image size")
parser.add_argument("-work_dir",type =str, default = "result/log.txt", help ="set work dir ")
parser.add_argument("--name",type =str, dest="nm", default = "result", help ="set name ")
parser.add_argument("--names","--ns", type =str,default = "re", help ="set name ")
parser.add_argument("--crop_size", nargs ="+", type = int, default = [128,129], help ="set crop size ")
args0= parser.parse_args("-batch_size 32 -work_dir result/log1.txt --image_type G --crop_size 128 120".split())
print(args0)
print(args0.batch_size) #64
print(args0.image_type) #Bparser.add_argument("--epochs",type= int, default=100,required=True)
args1 = parser.parse_args("--epochs 120".split())
print(args1.epochs)
"""
args1 = parser.parse_args() #将出现错误,因为required=True的参数,必须赋值
print(args1.epochs)
"""args1 = argparse.Namespace(batch_size = 100,data_path = "result/data.txt")
print(args1)with open("new_json.json","w") as fp:json.dump(args0.__dict__,fp, indent=4)