[IPython-user] Using yaml with ipython is goofy

Matthew Wilson matt@tplus1....
Sat Feb 14 16:19:48 CST 2009


I tried playing with yaml in an ipython session and got weird results.
yaml.load returned a string!

First, here's what happens in a not-ipython session:

    $ python
    Python 2.6b2+ (trunk:65208, Jul 23 2008, 17:02:49)
    [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import yaml
    >>> class Y:
    ...     pass
    ...
    >>> yaml.load("""
    ... !!python/object:__main__.Y
    ... name: Yahoo
    ... """)
    <__main__.Y instance at 0x82ec5ec>
    >>> type(yaml.load("""
    ... !!python/object:__main__.Y
    ... name: Yahoo
    ... """))
    <type 'instance'>


Now this is what happens in my beloved ipython:

    $ ipython
    /home/matt/virtualenvs/pitz-2.6/lib/python2.6/site-packages/ipython-0.9.1-py2.6.egg/IPython/Magic.py:38:
    DeprecationWarning: the sets module is deprecated
      from sets import Set
    Python 2.6b2+ (trunk:65208, Jul 23 2008, 17:02:49) 
    Type "copyright", "credits" or "license" for more information.

    IPython 0.9.1 -- An enhanced Interactive Python.
    ?         -> Introduction and overview of IPython's features.
    %quickref -> Quick reference.
    help      -> Python's own help system.
    object?   -> Details about 'object'. ?object also works, ?? prints more.

    In [1]: import yaml

    In [2]: class Y:
       ...:     pass
       ...: 

    In [3]: y = yaml.load("""
       ...: !!python/object:__main__.Y
       ...: name: Yahoo
       ...: """)


And then I got a big traceback, ending with:

    ScannerError: mapping values are not allowed here
      in "<string>", line 3, column 5:
        name: Yahoo
        ^

So, what is going on here?  What am I doing wrong?

Matt



More information about the IPython-user mailing list