Search code examples
ini

ini file - Refer variable from another ini file


How can I parse variable from another ini file?

In following example, I'd like to parse var_a from original_configuration.ini and use it at new_configuration.ini

original_configuration.ini:

[Section A]

var_a = "foo"

var_b = "bar"

new_configuration.ini:

[Section B]

var_c = "lorem"

var_d = {value of var_a in original_configuration.ini}

Solution

  • Since an INI file is an informal standard it depends on the program which is using the configuration file:

    The INI file format is an informal standard for configuration files for some platforms or software. INI files are simple text files with a basic structure composed of sections, properties, and values.

    Neither Wikipedia nor Microsoft's page about INI configuration files mention anything about referring to other properties or other configuration files. However, since it is not a formal standard, each configuration parser can have its own variant. This answer for example, shows that Python's configparser package can refer to other properties:

    [env]
    name = DEV
    
    [dir]
    home = /home/${env:name}/scripts