0

I wrote

parser.add_argument("n_tasks", default=20, help='Number of tasks to start')

and was expecting, that absense of argument will default it to 20. Althoug it writes

usage: get_sentinel_spawner.py [-h] n_tasks
get_sentinel_spawner.py: error: the following arguments are required: n_tasks

why?

Dims
  • 47,675
  • 117
  • 331
  • 600
  • 2
    You are defining a positional argument. By default, they are required arguments. However, the [documentation](https://docs.python.org/3/library/argparse.html#nargs) does say that `nargs='?'` should make a positional argument optional. However, I'm unsure what happens to the order of the arguments if such a positional argument is in the middle. I would have those kinds of arguments at the very end of the list. – Kendas Nov 09 '17 at 11:17
  • You could also turn it into an optional argument by putting a double dash in front of the name, like so: `parser.add_argument("--n_tasks", default=20, help='Number of tasks to start')` – Arne Nov 09 '17 at 11:20

0 Answers0