Save/dump a YAML file with comments in PyYAML

前端 未结 3 782
臣服心动
臣服心动 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:36

    PyYAML throws away comments at a very low level (in Scanner.scan_to_next_token).

    While you could adapt or extend it to handle comments in its whole stack, this would be a major modification. Dumping (=emitting) comments seems to be easier and was discussed in ticket 114 on the old PyYAML bug tracker.

    As of 2020, the feature request about adding support for loading comments is still stalling.

提交回复
热议问题