I want to output the yaml null but instead the python dumper is outputting a blank space instead.
I am using ruamel.yaml
{key: None}
Should output
key: null
instead it outputs
key:
I want to output the yaml null but instead the python dumper is outputting a blank space instead.
I am using ruamel.yaml
{key: None}
Should output
key: null
instead it outputs
key:
You should override the representer for None
, with your own:
import sys
import ruamel.yaml
def my_represent_none(self, data):
return self.represent_scalar(u'tag:yaml.org,2002:null', u'null')
yaml = ruamel.yaml.YAML()
yaml.representer.add_representer(type(None), my_represent_none)
data = {'key': None}
yaml.dump(data, sys.stdout)
which gives:
key: null