I have a file named test.py
. There are 3 ways to use it:
- You can load the contents of a json file, and it will generate graphs using that data (eg:
python test.py -l './data.json'
) - You can give it a YAML file, and it will use some information in it to generate a json file and then generate graphs (eg:
python test.py -y './user_input.yaml'
) - You can give it the information mentioned in point 2 through command line arguments (eg:
python test.py -s 50 -ftr '.pkl'
)
If -l
is used, it won't need any of the arguments used in 2 or 3. If -y
is used, it won't need any of the arguments from 1 and 2, and if the command-line arguments are given, it won't need any of the other arguments (but it will need the s and ftr arguments)
How would I set that up with argparse? One way would be to make if statements, and if args.yaml is not None: <load from the yaml file>
, but the problem with that is I would prefer an argument required error to pop up if option 3 is chosen but not all the arguments are given. Is there a way to use argparse that would satisfy my need?