Search code examples
pythonconfigobj

configobj multiple configurations


I am a new programmer working on a program that contains a list of recipes which can be searched and then generate menu from a selected commonality.

My initial thought has been to use a configuration file to store the data (I am using configobj for python). The problem here is that a value (e.g. ingredients = []) will occur several times.

Is there a way to separate different configurations within a single file? something like

Recipe
{
    value0 = 
}
Recipe 2
{
    value0 =
}

I am trying to avoid having ascending values (value1(n),value1(n+1)) or using a config file for each recipe.

Alternatively if this is not possible, could someone suggest an alternative file structure, including those not using configobj.


Solution

  • If you want human-editable ini-like format:

    [Recipe]
    value0 = ..
    
    [Recipe2]
    value0 = ..
    

    If the file is used to exchange data between programs then you could use (also human-readable) json format:

    { "Recipe": { "value0": ".." }, "Recipe2": { "value0": ".." } }