Create a yaml flow collection using PyYAML in Python

240 views Asked by At

I'm attempting to reproduce this YAML variable using PyYAML's dump:

x-google-backend:
  address: https://www.google.com
  path_translation: [ APPEND_PATH_TO_ADDRESS ]

Specifically the path_translation: [ APPEND_PATH_TO_ADDRESS ] is what I can't produce.

It's meant to take a python object and turn it into valid yaml. The trouble is I can only ever get

x-google-backend:
  address: https://www.google.com
  path_translation: '[ APPEND_PATH_TO_ADDRESS ]'

or

x-google-backend:
  address: https://www.google.com
  path_translation:
  - APPEND_PATH_TO_ADDRESS

From PyYAML's own documentation it looks like what I'm trying to do is called a "flow collection". But when I tried their recommended syntax I just got the above result with the hyphen representing a list item.

Specifically I'm doing it inside a dictionary:

dict({"path_translation": [ "APPEND_PATH_TO_ADDRESS" ]}, address="https://www.google.com")

Any ideas about how to produce this correctly would be greatly appreciated!

0

There are 0 answers