Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #6294
| From | Ben Finney <ben@benfinney.id.au> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Parse config file and command-line arguments, to get a single collection of options |
| Date | 2011-05-26 14:38 +1000 |
| Message-ID | <87k4deaxfc.fsf@benfinney.id.au> (permalink) |
| Organization | Unlimited download news at news.astraweb.com |
Howdy all, Python's standard library has modules for configuration file parsing (configparser) and command-line argument parsing (optparse, argparse). I want to write a program that does both, but also: * Has a cascade of options: default option values, overridden by config file options, overridden by command-line options. * Reads a different, or even additional, configuration file if specified on the command-line (e.g. --config-file foo.conf) and yet still obeys the above cascade. * Allows a single definition of an option (e.g. logging level) to define the same option for parsing from configuration files and the command line. * Unifies the parsed options into a single collection for the rest of the program to access without caring where they came from. How can I achieve this with minimum deviation from the Python standard library? (For anyone interested in gaining StackOverflow points, I'm also asking this as a question there so feel free to post answers on that site <URL:http://stackoverflow.com/questions/6133517/parse-config-file-and-command-line-arguments-to-get-a-single-collection-of-optio>.) -- \ “Apologize, v. To lay the foundation for a future offense.” | `\ —Ambrose Bierce, _The Devil's Dictionary_, 1906 | _o__) | Ben Finney
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Parse config file and command-line arguments, to get a single collection of options Ben Finney <ben@benfinney.id.au> - 2011-05-26 14:38 +1000 Re: Parse config file and command-line arguments, to get a single collection of options Raymond Hettinger <python@rcn.com> - 2011-05-25 22:15 -0700 Re: Parse config file and command-line arguments, to get a single collection of options rzed <rzantow@gmail.com> - 2011-05-28 23:12 +0000
csiph-web