Exclamation mark is a prefix for YAML tags. The parser has to implement a constructor for it by the tag name. There are some default tags like !!bool
, !!int
, etc. and even some Python specific tags like !!python/tuple
.
You can define your own constructors and even constructors for multiple tags caught by a prefix. By defining the prefix to ''
, you can catch all the tags and ignore them. You can return the tag and its value from the constructor to just treat it all as text.
>>> import yaml
>>> def default_ctor(loader, tag_suffix, node):
... print loader
... print tag_suffix
... print node
... return tag_suffix + ' ' + node.value
...
>>> yaml.add_multi_constructor('', default_ctor)
>>> yaml.load(y)
<yaml.loader.Loader object at 0xb76ce8ec>
!$uzy
ScalarNode(tag=u'!$uzy', value=u'')
{'world': {'people': {'name': '!$uzy', 'address': 'chez-bob'}}}
>>>