How can I do string concatenation, or string replacement in YAML?

后端 未结 7 2259
深忆病人
深忆病人 2020-12-01 08:38

I have this:

user_dir: /home/user
user_pics: /home/user/pics

How could I use the user_dir for user_pics? If I have to specify

7条回答
  •  萌比男神i
    2020-12-01 09:24

    If you are using python with PyYaml, joining strings is possible within the YAML file. Unfortunately this is only a python solution, not a universal one:

    with os.path.join:

    user_dir: &home /home/user
    user_pics: !!python/object/apply:os.path.join [*home, pics]
    

    with string.join (for completeness sake - this method has the flexibility to be used for multiple forms of string joining:

    user_dir: &home /home/user
    user_pics: !!python/object/apply:string.join [[*home, pics], /]
    

提交回复
热议问题