You want to use action='append' instead of nargs='+' :
>>> parser.add_argument("--name", dest='names', action='append') _AppendAction(option_strings=['--name'], dest='names', nargs=None, const=None, default=None, type=None, choices=None, help=None, metavar=None) >>> parser.parse_args('--name foo --name bar'.split()) Namespace(names=['foo', 'bar'])
nargs used if you just want to take a series of positional arguments, and action='append' works if you want to have the flag more than once and accumulate the results in the list.
source share