Python argparse dict arg
问题 I want to receive a dict(str -> str) argument from the command line. Does argparse.ArgumentParser provide it? Or any other library? For the command line: program.py --dict d --key key1 --value val1 --key key2 --value val2 I expect the following dictionary: d = {"key1": "val1", "key2": "val2"} 回答1: Here's another solution using a custom action , if you want to specify dict key pairs together comma-separated -- import argparse import sys parser = argparse.ArgumentParser(description='parse key