If you do yaml.dump without setting anything, the reference function will be used. It may not be necessary.
import yaml
person = {
"name": "foo",
"age": 20
}
d = [person, person]
print(yaml.dump(d))
For example, the output is as follows.
- &id001 {age: 20, name: foo}
- *id001
You can pass the Dumper option to yaml.dump. Then, the ignore_aliases () method of the Dumper class passed here should return True.
class IgnoreReferenceDumper(yaml.Dumper):
def ignore_aliases(self, data):
return True
print(yaml.dump(d, Dumper=IgnoreReferenceDumper))
Peace has come.
- {age: 20, name: foo}
- {age: 20, name: foo}
Recommended Posts