Save/dump a YAML file with comments in PyYAML

前端 未结 3 783
臣服心动
臣服心动 2020-12-05 03:53

I have a yaml file that looks like this:

# The following key opens a door
key: value

Is there a way I can load and dump<

3条回答
  •  北海茫月
    2020-12-05 04:41

    I have a branch of pyyaml that does exactly this. https://github.com/pflarr/pyyaml

    To build a yaml file with comments, you have to create an event stream that includes comment events. Comments are currently only allowed before sequence items and mapping keys.

    This only currently works for python3, I haven't ported it to the python2 version of the library, but could easily do so on request. Additionally, this should also be fairly easy to port to the C libyaml as well, as the python code is a simple port of that anyway.

提交回复
热议问题