On Tue, Oct 19, 2004 at 08:00:23AM -0700, Guido van Rossum wrote: > Let me suggest two variations that I have used successfully in my day > job (which is also my night job :). > > 1. For parsing .ini files, I wrote a wrapper around ConfigParser. The > Python-level API looks like this (anonymized and idealized): > > from XXX import MyConfigWrapper, optstr, optint, optbool, optfloat > > class Config(MyConfigWrapper): > poll_time = optfloat("network-parameters", "poll-time") > use_ssl = optbool("network-parameters", "use-ssl") > window_title = optstr("ui-parameters", "window-title") > # etc. I'm surprised no one has mentioned optparse yet. It already has all the features you use in this example. Maybe a similar API for configuration file parsing would be nice, if only for the sake of consistency: parser = ConfigParser() parser.add_option("network-parameters", "poll-time", type="float", dest="poll_time") parser.add_option("network-parameters", "use-ssl", type="bool", dest="use_ssl") parser.add_option("ui-parameters", "window-title", type="float", dest="window_title") options = parser.parse_file('foo.conf') print options.window_title print options.use_ssl # etc. Bonus points if the implementation allows me to specify a command-line option and configuration file option with one call, as in docutils [1]. More bonus points for reusing optparse code. Cheers, Johannes [1] http://cvs.sourceforge.net/viewcvs.py/docutils/docutils/docutils/frontend.py?rev=HEAD&view=auto
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4