I am trying to construct a yaml document by using a recursive function returning defaultdict on arbitrary levels from this stackoverflow recipe. Python 3.8.2
from collections import defaultdict
import yaml
def ret_dd():
return defaultdict(ret_dd)
yml = ret_dd()
yml['a']['b']['c'] = 1
with open('newfile.txt','w') as f:
yaml.dump(yml, f)
The outcome of the file I'm writing to I would like to see:
a:
b:
c: 1
however, what I'm seeing is:
!!python/object/apply:collections.defaultdict
args:
- &id001 !!python/name:__main__.ret_dd ''
dictitems:
a: !!python/object/apply:collections.defaultdict
args:
- *id001
dictitems:
b: !!python/object/apply:collections.defaultdict
args:
- *id001
dictitems:
c: !!python/object/apply:collections.defaultdict
args:
- *id001
What step am I missing?