Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #6294
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!news.alt.net!news.astraweb.com!border6.newsrouter.astraweb.com!not-for-mail |
|---|---|
| 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 |
| X-Public-Key-ID | 0xAC128405 |
| X-Public-Key-Fingerprint | 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 |
| X-Public-Key-URL | http://www.benfinney.id.au/contact/bfinney-pubkey.asc |
| X-Post-From | Ben Finney <bignose+hates-spam@benfinney.id.au> |
| Date | Thu, 26 May 2011 14:38:31 +1000 |
| Message-ID | <87k4deaxfc.fsf@benfinney.id.au> (permalink) |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) |
| Cancel-Lock | sha1:mOghOn1cJ1VCrjjaguZwnmJ0wAo= |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 8bit |
| Lines | 33 |
| Organization | Unlimited download news at news.astraweb.com |
| NNTP-Posting-Host | e35d83b7.news.astraweb.com |
| X-Trace | DXC=@lFQ7FE;CD44K?0c7HD\@7L?0kYOcDh@:N7:H2`MmAU3S2kSQZD<P_;]G;2>V^?kW3bEW9A[5UK?5NZ[SL`C\Kg3<]OBQ:]oZS4 |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:6294 |
Show key headers only | View raw
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