I’ve been using optparse for a while now, and would like to add the ability to load the arguments from a config file.
So far the best I can think of is a wrapper batch script with the arguments hardcoded… seems clunky.
What is the most elegant way to do this?
I agree with S.Lott’s idea of using a config file, but I’d recommend using the built-in ConfigParser (configparser in 3.0) module to parse it, rather than a home-brewed solution.
Here’s a brief script that illustrates ConfigParser and optparse in action.
Output:
Run with “
parser.py --language=French“:Help is built in.
Run with “
parser.py --help“:The config file: