pyyaml.dump()
has an allow_unicode
option that defaults to None
(all non-ASCII characters in the output are escaped). If allow_unicode=True
, then it writes raw Unicode strings.
yaml.dump(data, ff, allow_unicode=True)
Bonus
You can dump JSON without encoding as follows:
json.dump(data, outfile, ensure_ascii=False)