Efficient configuration storage

sebsauvage gg20040922.5.sebsauvage at spamgourmet.com
Wed Sep 22 10:32:38 EDT 2004


Hello.

In one of my programs ( http://sebsauvage.net/python/webgobbler/ ),
I have a global dictionnary containing the whole program configuration.
Sample follows:
CONFIG = { "network.http.useproxy" : True,
           "network.http.proxy.address": "proxy.free.fr",
           "network.http.proxy.port"    : 3128
           [etc.]
          }

I'd like to be able to save/load to/from a file.

I do not want to use pickle because I want configuration to be human readable.

ConfigParser could do the trick, but the biggest trouble is that it does
not retain type (boolean, integer, string...).

Would I have to store everything as text and cast it everywhere
it's used (and try/except each cast of course) ?
'Looks ugly and inefficient to me.

Or have a configuration class which knows the type of each parameter
and casts appropriately from the configuration file ?


Is there a better way of doing this ?

--
Sébastien SAUVAGE
http://sebsauvage.net



More information about the Python-list mailing list