Harley Holcombe Harley Holcombe - 1 year ago 272
Python Question

Save/dump a YAML file with comments in PyYAML

I have a yaml file that looks like this:

# The following key opens a door
key: value

Is there a way I can
this data while maintaining the comment?

Answer Source

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 is already being discussed.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download