I have seen questions about passing in dictionaries and lists to Python using the argparse library. The examples all show what my Python code looks like. But none show me what they look like on the command line. Where do I need braces, brackets, and quotes?
So if I wanted parameters --my_dict and --my_list how would I specify them as called from the command line?
Here is the essence of what I want to accomplish:
Python foo.py --my_dict="{'Name': 'Zara', 'Class': 'First'}" --my_list="['a', 'b', 'c']"
dictis actually just a string which you need to parse into a dictsys.argv[1:]to see the list of strings that the shell has passed to your script. You need enough quotes to keep the shell from splitting the strings. Whether you need brackets or braces depends on how you intend to parse the resulting string. The JSON route gives the greatest flexibility.nargs='+'? Then you can input "--mylist a b c", without added quotes or brackets.--student Zara First, and build the appropriate dict from the resulting tuple.