[IPython-dev] ipipe news

Walter Dörwald walter at livinglogic.de
Thu Mar 2 12:10:23 CST 2006


John Hunter wrote:

>>>>>> "Walter" == Walter Dörwald <walter at livinglogic.de> writes:
>     Walter> Here's the first patch:
>     Walter> http://styx.livinglogic.de/~walter/IPython/ipipe.diff
> 
> This morning I was thinking about the usefulness of an object browser
> class "iobj", that does a dir on an object and reports the attribute
> names in the first class and the attribute values in the right.
> Something like
> 
>   myobj | ifilter("not attr.startswith('_')") | ibrowse

You should be able to do:
myobj.__dict__ | ifilter("not key.startswith('_')") | ibrowse

Unfortunately this is currently broken, but I sent a patch to Ville a 
few minutes ago that fixes this problem.

> In the browser, you would want to be able to enter the object as an
> object.  Eg, if you have an array attribute, pressing "E" browses the
> array as a sequence and pressing "o" would browse it as an object,
> listing the array attributes.

In theory there are already different enter modes, but none of the 
objects implemented in ipipe use this yet.

How an object is entered is defined in the global function xiter(). 
There's hardcoded handling for dicts, modules and multi-line strings, 
for everything else the __xiter__() method of the object is called, if 
this doesn't exist, it falls back to __iter__(). If this doesn't exist 
either, you'll get the "Iteration over non-sequence" exception.

I guess I really need to document the existing extension points.

> Or does something like this already exist?

Not really, but you could implement an iobj class that provides two 
enter modes in __xiter__() when mode is None: one for "enter as 
sequence" and one for "enter object attributes". The problem is, that 
you don't have those iobj objects as attributes in an existing listing. 
Maybe this treatment should be the default fallback handling in xiter()?

Bye,
    Walter Dörwald




More information about the IPython-dev mailing list