Created
November 5, 2024 08:01
-
-
Save cdmatta/d821e902bd460e804f6c755c2a934b64 to your computer and use it in GitHub Desktop.
Python dump yaml to text correctly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import yaml | |
# https://stackoverflow.com/questions/25108581/python-yaml-dump-bad-indentation | |
class FixIndentationDumper(yaml.Dumper): | |
def increase_indent(self, flow=False, indentless=False): | |
return super(FixIndentationDumper, self).increase_indent(flow, False) | |
def yaml_dump(obj: dict) -> str: | |
return yaml.dump(obj, Dumper=FixIndentationDumper, default_flow_style=False, sort_keys=False, width=200) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment