[Tutor] Writing a Configuration Facility for an Application

Kent Johnson kent37 at tds.net
Fri Jan 30 13:53:08 CET 2009


On Fri, Jan 30, 2009 at 7:40 AM, Wayne Watson
<sierra_mtnview at sbcglobal.net> wrote:
> I'm about to provide a config file for an application I've been working
> with.

> I suspect there may be a standard way of doing this in Python that relies on
> more complex operations that simplify matters than just reading the file one
> line at a time. Dictionaries?  Comments?

One possibility is to put the settings in a dictionary and use the
pickle module to save and restore the dict. This is pretty simple. The
pickled file is not particularly readable, though.
http://docs.python.org/library/pickle.html

Another way is to use a .ini file. The ConfigParser module can read
ini files but not write them.
http://docs.python.org/library/configparser.html

There are add-on modules that implement read-write ini files, for example
http://www.voidspace.org.uk/python/configobj.html

Kent


More information about the Tutor mailing list