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

Darren Dale dsdale24@gmail....
Wed Sep 30 11:35:25 CDT 2009


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


More information about the IPython-dev mailing list