[IPython-user] IPython 0.7.1 is out.

Walter Dörwald walter at livinglogic.de
Tue Jan 24 08:52:58 CST 2006


Ville Vainio wrote:

> On 1/24/06, Walter Dörwald <walter at livinglogic.de> wrote:
> 
>> Sounds great! Can you show an example for installing a display hook? Is
>> it OK to just use print in the hook, or do I have to use IPython's
>> output facility?
> 
> Too busy to verify right now, but the hook name is "results_display".
> hooks.py has the default implementation, you can do
> ipapi.set_hook("results_display",my_display_hook) to set your own.

Actually it's "result_display", here's what I'm using now:

import __builtin__
if hasattr(__builtin__, "__IPYTHON__"):
    from IPython import ipapi, hooks

    @ipapi.ashook("result_display")
    def displayhook(self, obj):
       if isinstance(obj, type) and issubclass(obj, Table):
          obj = obj()
       if isinstance(obj, Table):
          obj = obj | defaultdisplay
       if isinstance(obj, Display):
          return obj.display()
       else:
          raise hooks.TryNext

Is hasattr(__builtin__, "__IPYTHON__") the correct way to determine if 
I'm running under IPython?

>> BTW, the TryNext exception should be available in the IPython.ipapi module.
> 
> I thought so too, I'll move TryNext to ipapi.

OK.

>> Another enhancement request: It would be great if the return value of
>> the displayhook would be assigned to the _ variable (instead of the
>> original object). This way e.g. a curses based browser could be used to
>> select an object from a list, pressing a key returns to the IPython
>> shell with the picked objects as _.
> 
> I will explore this, sounds good.
> 
> BTW, I figured I'll put your generator pipe utilities to Extensions
> dir, once you get the displayhooks & all properly set up.

I'm making good progress on the curses-based browser (I find programming 
curses actually fun). Here are a few screenshots:

Browsing the result of:

ils("/usr/local/lib/python2.4/site-packages/IPython") | 
isort("len(name),name.lower()") | iwide

See http://styx.livinglogic.de/~walter/IPython/directory.gif

(I've switched to | as the piping character, as this makes it possible 
to use + for chaining, i.e. you can use ipwd + igrp to browse a combined 
list of the /etc/passwd and /etc/groups entries.

You can browse anything that's iterable, the following gives you a 
simple text viewer:
open("/usr/local/lib/python2.4/site-packages/IPython/ipapi.py") | ibrowse

See http://styx.livinglogic.de/~walter/IPython/file.gif

It's possible to browse database content too:
 >>> from ll import orasql
 >>> db = orasql.connect(...)
 >>> c = db.cursor()
 >>> c.execute("select * from buildlog_select order by r_id desc, 
bl_lineno asc")
 >>> c | ibrowse

See http://styx.livinglogic.de/~walter/IPython/sql.gif

Bye,
    Walter Dörwald




More information about the IPython-user mailing list