Can't pass a Python list on command line with zsh as shell

Viewed 586

I am trying to add an optional command line argument that takes in a list using argparse. I am currently specifying the argument as follows (note there are other command line arguments as well, but I seem to be having issues with the following one because it is a list as opposed to a single string or number).

parser.add_argument("--num_objects", nargs='+', type=int, default=[2, 4, 8],
  help="Number of objects at each time")

However, when I try to run the script python game.py --num_objects=[4, 8, 12], I get the error zsh:1: no matches found: --num_filters=[4, 8, 12]. How do I fix this?

1 Answers

You need to surround the list in 'single quotes', to prevent Zsh from interpreting it as a pattern:

python game.py --num_objects='[4, 8, 12]'

Alternatively, you can tell Zsh to not interpret any of the input as patterns:

noglob python game.py --num_objects=[4, 8, 12]
Related