Best way to store config or preferences in a multi-platform way.

Ivan Illarionov ivan.illarionov at gmail.com
Thu May 1 16:50:32 EDT 2008


On Thu, 01 May 2008 11:56:20 -0700, Carl Banks wrote:

> On May 1, 1:30 pm, Ivan Illarionov <ivan.illario... at gmail.com> wrote:
>> On Thu, 01 May 2008 09:45:28 -0700, Carl Banks wrote:
>> > On May 1, 12:11 pm, Jon Ribbens <jon+use... at unequivocal.co.uk> wrote:
>> >> On 2008-05-01, Ivan Illarionov <ivan.illario... at gmail.com> wrote:
>>
>> >> > IMO .ini-like config files are from the stone age. The modern
>> >> > approach is to use YAML (http://www.yaml.org).
>>
>> >> You mean YAML isn't a joke!? It's so ludicrously overcomplicated,
>> >> and so comprehensively and completely fails to achieve its stated
>> >> main goal of being "readable by humans", that I had assumed it was
>> >> an April Fool along the lines of Intercal or brainf***.
>>
>> > YAML, ISTM, took a simple concept that worked for small,
>> > straightforward data, and tried to make into a format that could
>> > anything anywhere, with disastrous results.  It's not unlike Perl in
>> > this regard.  It's quite ridiculous.
>>
>> > My recommendation to the OP would be:
>>
>> > If you intend to write a GUI that completely sets all the options,
>> > use XML.  You can bet there are some users who would prefer text
>> > editing options files, and XML, while not the most readable format
>> > available, at least gives users the option.
>>
>> > If you don't intend to write a GUI to do that, write a simple text
>> > file parser (if the options are simple), use ConfigParser, or use a
>> > Python file that you exec.
>>
>> > Store the file in $HOME/.appname/config.ext on Unix, $USERDIR/
>> > ApplicationData/Appname/config.ext on Windows.  I don't recommend
>> > using the Windows registry to store options; use it to modify Windows
>> > behavior (like file associations) but keep your own program's options
>> > in your own file.
>>
>> If you don't like YAML, use JSON or something similar -- XML is
>> overkill and .INI is too limited.
> 
> 
> I don't think you know the OP's requirements enough to know whether INI
> or XML is suitable. You're welcome to suggest alternatives but what I
> suggested is fine.
>
> As for XML being overkill for anything, I highly disagree. XML is
> suitable for the smallest tasks.  These days I use XML for almost all my
> data exchange needs: including conf files.  Elementtree makes it
> possible to process XML and pull out some typical data in ten or so
> lines of code.  What could possibly be overkill about that?
> 
> 
> Carl Banks

I used XML for almost everything in the past until I found YAML. 
Elementtree makes it easy but not easy enough. The most powerful thing 
about YAML is that it was designed to map directly to native data types 
in languages like Python (see another my post in this thread for 
example). And this means that simple YAML files will always be easier to 
process in Python than XML or INI. And this in turn means that OP with 
any requirements will have to write less code to read and write his 
config files.

-- 
Ivan



More information about the Python-list mailing list