def rewrite_yml(data): with io.open('toc.yml', 'w', encoding='utf8') as outfile: yaml.dump(data, outfile, default_flow_style=False, allow_unicode=True)