How can I generate Hocon conf file dynamically using pyhocon in Python 3?

前端 未结 2 1185
野性不改
野性不改 2021-01-14 04:24

I would like to use automation to create the hocon configuration with python 3 scripting. I read that lightbend (https://github.com/lightbend/config) recommends pyhocon (ht

2条回答
  •  無奈伤痛
    2021-01-14 05:16

    Probably this example will answer your question

    from pyhocon.converter import HOCONConverter
    import pyhocon
    
    string = '{"Environment": "Dev","Test": ${Environment}}'
    factory = pyhocon.ConfigFactory.parse_string(string, resolve=True)
    factory.put('somekey','somevalue')
    print(HOCONConverter().to_hocon(factory))
    

    returns

    Environment = "Dev"
    Test = "Dev"
    somekey = "somevalue"
    

提交回复
热议问题