Windows控制台给python传入字典参数

明明很简单的,害的老子搞了两个多小时?

 

parser.add_argument("params", default=None, type=None,
                 dest='params', help='need to be implement')

after args=parser.parse_args() is used, send a string params to args.params,
the format is like:
"{'key':value,'key2':"string"}"

then use the code below make the string change to a dict, the apply to the args.params

dict_value = eval(args.params)
args.params = dict_value

  

posted @ 2021-07-09 09:54  大浪淘沙、  阅读(107)  评论(0)    收藏  举报