Neetesshhr
Neetesshhr

Reputation: 503

How to read $xyz value from .properties file in python?

I have a build.properties file like

[directory]
src = src
srcdir = ${src}/fix
srcext = ${srcdir}/extensions
srct = ${srcext}/xyz

my aim is to get the full value of srct i mean it is to be src/fix/extensions/xyz

Is there any way of getting the value of cde? I tried configparser and jproperties but i couldn't get the required output.

Upvotes: 0

Views: 174

Answers (1)

user459872
user459872

Reputation: 24562

You can use ExtendedInterpolation class which implements more advanced syntax.

>>> from configparser import ConfigParser, ExtendedInterpolation
>>> 
>>> parser = ConfigParser(interpolation=ExtendedInterpolation())
>>> parser.read("build.properties")
['build.properties']
>>> print(parser["directory"]["srct"])
src/fix/extensions/xyz

Upvotes: 2

Related Questions