0

I have multiple configuration files and I want to read a different config file based on which option I type. For example if I type in the terminal

python test.py -60min

I want to read the python script to read the config file '/home/matt/config_60min.ini'

Similarly, python test.py -30min would read '/home/matt/config_30min.ini'

I'm not sure if this would be done using conditional logic within the script or with a simple option parser. Maybe there's a better way to go about it such as python test.py -f 60min

Thanks in advance.

1 Answer 1

1

You could do it like this:

import sys
config_path = '/home/matt/config_{}.ini'.format(sys.argv[1])

and run the script using:

python test.py 60min

If it gets more complicated than this, consider using the argparse library

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.