简体   繁体   中英

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

I have a build.properties file like

abc = xyz
cde = ${abc}/tuv

my aim is to get the full value of cde i mean it is to be xyz/tuv

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

You can use ExtendedInterpolation class which implements more advanced syntax.

from configparser import ConfigParser, ExtendedInterpolation

parser = ConfigParser(interpolation=ExtendedInterpolation())
with open("build.properties") as f:
    parser.read_string("[DUMMY_SECTION]\n" + f.read())

print(parser["DUMMY_SECTION"]["cde"])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM