Is it possible to reference a variable within an ini from another section?
I know you can do the following
[env]
dir = /home/a
dir2 = %(dir)s/b
But what happens if I have two sections and want to reference the variable from that section?
[env]
name = DEV
[dir]
home = /home/<name from env here>/scripts
Thanks
See the documentation on configparser
. Create a parser with extended interpolation. Use ${section:option}
syntax to reference options from other sections.
from configparser import ConfigParser, ExtendedInterpolation
parser = ConfigParser(interpolation=ExtendedInterpolation())
parser.read_string('''[env]
name = DEV
[dir]
home = /home/${env:name}/scripts
''')
print(parser['dir']['home'])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With