Set nargs
of the data
argument to nargs="+"
(meaning one or more) and type to int
, you can then set the arguments like this on the command line:
--data 1 2 3 4
args.data
will now be a list of [1, 2, 3, 4]
.
If you must have a tuple, you can do:
my_tuple = tuple(args.data)
Putting it all together:
parser = argparse.ArgumentParser()
parser.add_argument('--data', nargs='+', type=int)
args = parser.parse_args()
my_tuple = tuple(args.data)