Using ruamel.yaml in Python, if I dump with the SafeRepresenter or RoundTripRepresenter and default_flow_style the default, null is represented as expected.
from ruamel.yaml import YAML
yaml = YAML(typ='rt')
yaml.dump({'key1': None, 'url': 'https://lala/', 'key2': None}, sys.stdout)
key1:
url: https://lala/
key2:
However, if I change the default_flow_style to None, the representer for null seems to be ignored and instead null is represented as !!null '' eg.
from ruamel.yaml import YAML
yaml = YAML(typ='rt')
yaml.default_flow_style = None
yaml.dump({'key1': None, 'url': 'https://lala/', 'key2': None}, sys.stdout)
key: {key1: !!null '', url: https://lala/, key2: !!null ''}
Setting the representer for null explicitly makes no difference eg.
SafeRepresenter.add_representer(type(None), RoundTripRepresenter.represent_none)
I tried the above, but output for null when using the SafeRepresenter instead of the RoundTripRepresenter was still !!null '' when using default_flow_style=None.
How do I output null instead of !!null '' when using default_flow_style=None directly from ruamel.yaml rather than doing postprocessing on its output (eg. a find replace)?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…