I think the question is self explanatory. I would like to use a list of list as a command line argument like so:
python3 awesome_code.py --list=[[var1,var2],[var3,v4]..]
Is this possible at all?
I think the question is self explanatory. I would like to use a list of list as a command line argument like so:
python3 awesome_code.py --list=[[var1,var2],[var3,v4]..]
Is this possible at all?
You could use argparse
to define a more typical shell command line like this:
python3 awesome_code.py --list v1 v2 --list v3 v4
Where the result would be
[['v1', 'v2'], ['v3', 'v4']]
Here is the example code:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
'--list',
action='append',
nargs='*',
)
args = parser.parse_args('--list v1 v2 --list v3 v4'.split())
print(args.list)