pyyaml: dumping without tags

Paul Tarjan picture Paul Tarjan · Dec 23, 2009 · Viewed 33.9k times · Source

I have

>>> import yaml
>>> yaml.dump(u'abc')
"!!python/unicode 'abc'\n"

But I want

>>> import yaml
>>> yaml.dump(u'abc', magic='something')
'abc\n'

What magic param forces no tagging?

Answer

interjay picture interjay · Dec 23, 2009

You can use safe_dump instead of dump. Just keep in mind that it won't be able to represent arbitrary Python objects then. Also, when you load the YAML, you will get a str object instead of unicode.