Command line arguments are always passed as strings. You will need to parse them into the desired data type yourself.
>>> input = "[2,3,4,5]" >>> map(float, input.strip('[]').split(',')) [2.0, 3.0, 4.0, 5.0] >>> A = map(float, input.strip('[]').split(',')) >>> print(A, type(A)) ([2.0, 3.0, 4.0, 5.0], <type 'list'>)
These are libraries like argparse and click that allow you to define your own type conversion of argument types, but argparse treats "[2,3,4]" same as [ 2 , 3 , 4 ] so I doubt it would be useful.
edit January 2019 This seems to have worked a bit more, so I will add another option, taken directly from the argparse documentation.
You can use action=append to allow duplicate arguments in a single list.
>>> parser = argparse.ArgumentParser() >>> parser.add_argument('--foo', action='append') >>> parser.parse_args('--foo 1 --foo 2'.split()) Namespace(foo=['1', '2'])
In this case, will you pass --foo? once for each item in the list. OP usage example: python filename.py --foo 2 --foo 3 --foo 4 --foo 5 will result in foo=[2,3,4,5]