[Tutor] How do you implement a config file?
Tracy R Reed
treed at ultraviolet.org
Sun Jul 16 04:27:39 CEST 2006
I am writing a small python application that needs a few variables to be
end user configurable. Right now I just have the variables right up
front where the user can tweak them in the program code and a big
commented line that says "Nothing editable past this point." But I would
like to be able to break this out into a separate config file. There are
two ways I see to do this:
1. Use ConfigParser. But from all of the docs and examples I see
ConfigParser only accepts name=value type pairs. How can I implement a
list or a dictionary of configs in ConfigParser?
Part of my config involves things like:
foo = ['bar','baz','bah']
How would I represent this cleanly in config parser? Saying:
foo1 = bar
foo2 = baz
foo3 = bah
is not scalable as the list can be arbitrarily long. It might also
suffice if I could just put the actual python code where these variables
are defined into a config file and have it read into the main file. But
I don't see any good way to do that either without actually making my
config file a module and calling it config.py instead of application.config.
Suggestions?
--
Tracy R Reed
http://ultraviolet.org
More information about the Tutor
mailing list