Config file for Python with repeated sections/objects
Question: I would like to store this kind of configuration, with repetition of sections
and the keys within each:

    
    
    [item]
    name = 'name1'
    url = 'address1'
    whatever_var = 'foo1'
    
    [item]
    name = 'name2'
    url = 'address2'
    whatever_var = 'foo2'
    
    ...
    

What config file format would be adequate for such structure?: ConfigParser,
ConfigObj, JSON, YAML,...? I have never used any (Python newcomer) and would
like to know which one fits best.

Note: I am using Python 2.7 so far.

[EDIT]: Well, I believe it's not just a duplicate question, because I need not
just duplicated keys, but: \- duplicated sections (with their unique keys
inside, which cannot be bropued with other keys from other sections)

Also, I don't ask how to do it in ConfigParser, but which file type fits
better in this situation (XML, JSON, custom file,...). In fact, I think that
what I want cannot be obtained with ConfigParser nor ConfigObj, and I might
try XML, even if it is a bit less human-readable. And, hey, it's never a waste
of time learning to deal with XML files.


Answer: It looks like you are going to store data in files and you are leaving out the
idea of using databases and other types of interactions with remote servers to
keep this stuff. Glad you have that straightened out.

Many file types will support this type of data if the data is small. (if it'll
fit on your machine). If the data gets to be too big or takes too long to
access due to billions of records then you have different problems.

Sometimes the domain of the problem affects which file type to use. If you are
making a webserver then you might want to go with JSON or XML for transmission
purposes.

If you want to use the format that you have spelled out in your post here is
how to read the file.

    
    
    import configparser
    
    conf = configparser.ConfigParser()
    
    conf.read('FILE.INI')
    

-here is how to read a value from the file you read (and assuming your [item] will have a unique titles like [Person1])
    
    
    conf['Person1']['name']
    

-and then writing the file is pretty close to normal
    
    
    with open('FILE.INI', 'w') as inifile:
    
        conf.write(inifile)
    

