I am writing yaml file like this
with open(fname, "w") as f: yaml.safe_dump({'allow':'', 'deny': ''}, f, default_flow_style=False, width=50, indent=4)
This outputs:
allow: ''
I want to output as
allow:
How can I do that?
Empty values: null can be used to represent an empty value, such as an empty list or an empty string. Placeholder values: null can be used as a placeholder value when the actual value is not yet known.
Nulls in YAML can be expressed with null or ~ .
As you can see, since both l-document-prefix and l-any-document are optional, an empty YAML stream is valid – but contains no document. If you're asking whether l-any-document can produce the empty string, the answer is no.
For None
type to be read from python use null
in yaml
A YAML file test.yml
like this
foo: null bar: null
will be read by python as
import yaml test = yaml.load(open('./test.yml')) print(test) foo: None bar: None
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With