[IPython-dev] ip.core.ipapi.get

Brian Granger ellisonbg.net@gmail....
Wed Sep 30 12:21:07 CDT 2009


This function is essentially deprecated.  This is a bug though that
you are getting an exception.  But, in the mean time please call the
following function:

In [1]: ip = get_ipython()

This function is always available inside IPython and returns basically the
same
thing as get used to.

For the curious, the problem with the old ipapi.get is that it assumed that
there
was always only ONE ipython and it returned that one.  The new get_ipython
function is smart: it doesn't assume there is only 1 ipython, and it always
returns
the right one.

Cheers,

Brian

On Wed, Sep 30, 2009 at 9:35 AM, Darren Dale <dsdale24@gmail.com> wrote:

> I think ip.core.ipapi.get() is behaving differently in the trunk than
> it did before the refactor. Here is the new implementation:
>
> def get():
>    """Get the most recently created InteractiveShell instance."""
>    from IPython.core.iplib import InteractiveShell
>    insts = InteractiveShell.get_instances()
>    most_recent = insts[0]
>    for inst in insts[1:]:
>        if inst.created > most_recent.created:
>            most_recent = inst
>    return most_recent
>
> If I call get from the python prompt, instead of Ipython, I used to
> get None, but now I get an error because insts is an empty list so
> insts[0] raises an IndexError. Perhaps:
>
> def get():
>    """Get the most recently created InteractiveShell instance."""
>    from IPython.core.iplib import InteractiveShell
>    insts = InteractiveShell.get_instances()
>    if not insts:
>        return None
>    most_recent = insts[0]
>    for inst in insts[1:]:
>        if inst.created > most_recent.created:
>            most_recent = inst
>    return most_recent
>
>
> Darren
> _______________________________________________
> IPython-dev mailing list
> IPython-dev@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/ipython-dev/attachments/20090930/27b73b2a/attachment.html 


More information about the IPython-dev mailing list