1

I've been always using ConfigParser. Now that I have the need of using nested sections, I've found ConfigObj which seems to fit really my needs. The problem comes when I try to interpolate variables from other subsections. Is this possible? Otherwise the nested sections stop making sense in my case.

I have been looking for the interpolation syntax in configobj and it looks like this has not been implemented... I just wanted to be sure and to know other options to deal with this.

This is an example of what I would like to do:

[global]
    [[dirs]]
        software = /path-to-software-dir/
        dbs = /path-to-dbs-dir/

[A]
    [[softs]]
        soft1 = {global.dirs.software}/soft1
        soft2 = {global.dirs.software}/soft2
    [[dbs]]
        db1 = {global.dirs.dbs}/db1
        db2 = {global.dirs.dbs}/db2

Any ideas?

Pau RS
  • 86
  • 6
  • have you read the [configobj documentation](https://configobj.readthedocs.io/en/latest/configobj.html#string-interpolation)? – Francesco Montesano Jan 15 '18 at 07:40
  • Yes, I have seen that it hierarchically looks for the variable in the current 'default' subsection from child to parent sections... But this still doesn't fit my needs. I have several parent sections (equivalent to A in my example) and I really need this structure – Pau RS Jan 15 '18 at 07:46
  • I would say that it is not possible. I would suggest you to open an issue on the project [github page](https://github.com/DiffSK/configobj/issues) but fro m the lack of recent activity, it doesn't seem to me that this will help much – Francesco Montesano Jan 15 '18 at 08:20
  • Thanks! I will open an issue even it will probably be ignored. Any idea of how to solve this problem? I have been thinking on customizing the parser interpolation method... but seems to be really tough... – Pau RS Jan 15 '18 at 08:50

1 Answers1

0

We have had a similar problem. We ended up calculating the path in the application. This has the added advantage that you can normalize the path, using os.path.join() and friends.

TomK
  • 362
  • 2
  • 10