using names before they're defined
Bruno Desthuilliers
bdesth.quelquechose at free.quelquepart.fr
Fri Jul 28 03:31:54 EDT 2006
davehowey at f2s.com a écrit :
>>>Hiya, you might be interested in this alternative config parsing
>>>program:
>>>http://www.voidspace.org.uk/python/configobj.html
>>
>>Yes, I know it. But I don't like it. Either a simple ini file do the
>>trick, or I need a full blown app-specific DSL - which can be as simple
>>as a Python file with dicts, lists, etc !-)
>>
>>
>
>
> What do you mean? I don't really understand.
It's not a criticism of configobj - which is a quite nice package -,
it's just a matter of personal tastes (I don't like configobj's
[[[some-nested-sub-sub-section]]] syntax) and specific needs.
Most of the time, I don't need nothing more than a plain ini file - and
in this case, I prefer to use configparser because it's in the standard
lib (so I avoid a dependency on a 3rd part package).
When an ini file won't do, it's usually because what the app need is
really complex and specific enough to justify a "domain specific language".
And sometimes, this DSL can be expressed with Python's syntax, like for
example:
schema = {'turbine1': {'class': 'Turbine',
'upstream' : ('frobnicator2',),
'downstream' : () # nothing,
},
'frobnicator2' : {'class' : 'Frobnicator',
'upstream' : (),
'downstream' : ('frobnicator2',),
},
}
FWIW, the package's end user is not even supposed to know this is in
fact Python code !-)
FWIW, JSON can be a good candidate for this kind of stuff too.
More information about the Python-list
mailing list