Any Python Hackers Wanna Beta Test????
Tim Daneliuk
tundra at tundraware.com
Tue Mar 9 22:50:07 EST 2004
Dave Brueck wrote:
> Tim wrote:
>
>>One of the things I find myself needing over and over is providing an
>>external configuration file for use by my applications. For various
>>reasons, I have not been satisfied with other solutions to this problem
>>I have seen so far.
>>
>>So ...I am about 25% done with a new Python module I've wanted to write
>>for some time. It is intended as general purpose configuration file
>>parser complete with conditionals, variable substitution, etc. The idea
>>is that you hand it the name of a configuration file, and it returns a
>>populated symbol table, ready-to-use.
>
>
> Just curious, but does it offer much over just doing this:
>
> In a file called config.py:
>
> optionA = 'foo'
>
> optionB = 'bar'
>
> class Network:
> optionC = 'baz'
>
> And then in your application doing:
>
> import config
>
> config.optionA
> config.Network.optionC
>
> etc..?
>
> That's what I use now and it pretty much does everything I want - the dummy
> classes give an easy named hierarchy/grouping of values, and since it's just a
> Python module you also get built-in support for conditionals, variable
> substitution, etc. Also, you don't have to write code to do a bunch of syntax
> verification since Python does that for you. I've used this on several projects
> where the config file is editable by non-programmers and they haven't had any
> problems. I usually stick in the config all the documentation for each setting
> too.
>
> -Dave
>
>
How about something like this:
-------------------------------
# Uncomment one of the follow as appropriate
# WIN32 = Anyoldvalue
# UNIX = Anyoldvalue
HOMEDIR =
DIRLST =
.if [WIN32]
HOMEDIR = [$HOMEPATH]
STDCONFIG = [$HOMEPATH]\MyStuff\std.cfg
DIRLST = dir
.endif
.if [UNIX]
HOMEDIR = [$HOME]
STDCONFIG = /usr/local/etc/std.cfg
DIRLST = ls
.endif
# Go get default configuration
.include [STDCONFIG]
# Construct string representing dir listing appropriate for this OS
DIRLISTING = [DIRLIST] [HOMEDIR]
--
----------------------------------------------------------------------------
Tim Daneliuk tundra at tundraware.com
PGP Key: http://www.tundraware.com/PGP/
More information about the Python-list
mailing list