根据缺失信息调整异常消息

Adjust exception message basing on missing information

有这样的代码:

if __name__ == "__main__":
    parser.add_argument("--u_shape_dict", default="", action='store',
                    help="required for ...")

    parser.add_argument("--v_shape_dict", default="", action='store',
                    help="required for ...")

    u_shape_dict = args['u_shape_dict']
    if not u_shape_dict:
        raise Exception('u_shape_dict is missing. Please provide it')

    v_shape_dict = args['v_shape_dict']
    if not v_shape_dict:
        raise Exception('v_shape_dict is missing. Please provide it')

我想将这两个异常合二为一:

if not u_shape_dict or v_shape_dict:
    raise Exception('%s is missing. Please provide it' % )

可以吗? % 符号后实际上我需要放什么?

您应该使用 required 选项,argparse 会处理错误报告