[IPython-user] [Python-Dev] a quit that actually quits

Walter Dörwald walter at livinglogic.de
Wed Jan 4 16:35:07 CST 2006

Ville Vainio wrote:

> On 1/4/06, Fernando Perez <Fernando.Perez at colorado.edu> wrote:
>> Neat!  This is a nice hack, I've saved it and will play with it later.  Ville,
>> who's one of our resident ipython-as-shell diehards, might even 'ipythonize' it :)
> There certainly is potential for interesting uses... for the pipeline
> manipulation of "tables" that is.
> E.g. I'm thinking of
> findfiles('/tmp') / tablefilter('size > 10000 and
> name.lower().endswith(".cpp")')
> Where findfiles would output a "table" that it fills with all the
> basic file name & stat info, and "tablefilter" would dump all fields
> into locals() namespace and pass through only "lines" that pass
> "eval"-ing the argument string.

Or tablefilter could take a callable that gets passed the attributes as 
keyword arguments than I could do:

def bigcpp(size, name, **rest):
    return size>10000 and name.lower().endswith(".cpp")

findfiles('/tmp') / tablefilter(bigcpp)

Maybe we should have both. callables for building reusable components 
and 'eval'ed strings for ad hoc filter expressions.

But of course it should be simple to define a tablefilter that takes a 
callable, i.e. something like:

class tablefilter(Filter):
    def __init__(self, func):
       self.func = func

    def filter(self, item):
       attrs = dict((f, getattr(item, f)) for f in item.__shattrs__)
       return func(**attrs)

> It's interesting to see how the idea evolves. It's certainly a step
> into a more "structured" shell-like behaviour. In addition to
> findfiles() we could have table-emitting methods like getsvninfo() for
> version control stuff, mp3files() that would tabulate id3 info from
> all mp3 files etc...

And if we get the API right, it should be easily extensible with new 

    Walter Dörwald

More information about the IPython-user mailing list