In [1]:
%reload_ext yamlmagic
In [2]:
%%yaml
a_toplevel_key: 1
Out[2]:
which can be accessed by the special last result variable _:
In [3]:
_
Out[3]:
Or will update a named variable with the parsed document:
In [4]:
%%yaml x
- a: 1
b: 2
In [5]:
x
Out[5]:
By default, yaml.SafeLoader will be used, which won't allow the powerful but dangerous (and unportable) !python/ tags. If you'd like to use them, provide the -l (or --loader) argument with a BaseLoader subclass available via a local variable...
In [6]:
from yaml import Loader
class FooLoader(Loader):
# some special things you have built
pass
In [7]:
%%yaml --loader FooLoader
- a: !!python/float 1
b: !!python/float 2
Out[7]:
...or dotted-notation path to a loader:
In [8]:
%%yaml --loader yaml.Loader
- a: !!python/float 1
b: !!python/float 2
Out[8]:
Issues and pull requests welcome!
yamlmagic is released as free software under the BSD 3-Clause license.