Re: Any Python Hackers Wanna Beta Test????

From: Tim Daneliuk (tundra_at_tundraware.com)
Date: 03/10/04


Date: 09 Mar 2004 22:50:07 EST

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@tundraware.com
PGP Key:         http://www.tundraware.com/PGP/


Relevant Pages

  • Re: exe wont run
    ... workstations and more than one workstation is accessing the data how ... replaced with a copy of the repository version. ... Do this in case a configuration file with screen=off has not been ...
    (microsoft.public.fox.programmer.exchange)
  • Re: exe wont run
    ... My code does not allow for the updating of the loader program ... replaced with a copy of the repository version. ... Do this in case a configuration file with screen=off has not been ...
    (microsoft.public.fox.programmer.exchange)
  • Re: exe wont run
    ... My code does not allow for the updating of the loader program ... replaced with a copy of the repository version. ... Do this in case a configuration file with screen=off has not been ...
    (microsoft.public.fox.programmer.exchange)
  • Re: exe wont run
    ... My code does not allow for the updating of the loader program ... replaced with a copy of the repository version. ... Do this in case a configuration file with screen=off has not been ...
    (microsoft.public.fox.programmer.exchange)
  • Re: Any Python Hackers Wanna Beta Test????
    ... > external configuration file for use by my applications. ... > parser complete with conditionals, variable substitution, etc. ... Python module you also get built-in support for conditionals, ...
    (comp.lang.python)