Use dictionary for Python argparse
问题 I have a dictionary which maps human readable values to three different Python specific values. How can the argparse Python module use this dictionary to get me the specific values while the user can choice between the keys. Currently I have this: def parse(a): values = { "on": True, "off": False, "switch": None } parser = argparse.ArgumentParser() parser.add_argument("-v", "--value", choices=values, default=None) args = parser.parse_args(a) print("{}: {}".format(type(args.value), args.value)