S
sebsauvage
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 ?
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 ?