What INI config file module allows lists of duplicate same-named options?

Philip Semanchuk philip at semanchuk.com
Mon Jan 10 18:28:29 EST 2011


On Jan 10, 2011, at 6:05 PM, Ben Finney wrote:

> "Thomas L. Shinnick" <tshinnic at io.com> writes:
> 
>> Here, I need to list multiple file/dir path pairs.  A list of multiple
>> items to be acted upon in a common way.  It is a list.  Simple.
>> Except I can't find a library/pypi module with the obvious extension.
> 
> What you want is incompatible with calling the result “an INI file”,
> because that entails the restrictions you described.

I dunno about that. The INI file format isn't standardized so there aren't restrictions on what one can expect to find in an INI file other than people's expectations. I'll grant you that most INI files don't have (or expect) duplicate keys in a section, but I've seen some that do.


> You would be better advised to use a configuration format that can do
> what you want, such as YAML or JSON. Both of those have good Python
> support; JSON in particular has support in the standard library.

I second that, and the point above (about there being no standard that governs INI files) is another reason to avoid them. Some INI file libraries expect a hash mark as a comment, some expect semicolon, some make no allowances for non-ASCII encodings, some expect UTF-8 or ISO-8859-1 or Win-1252, some only allow '=' as the key/value separator, some allow other characters. INI files are nice and simple but there's devils in those details.

Cheers
Philip




More information about the Python-list mailing list