[IPython-dev] ipipe news
Fernando.Perez at colorado.edu
Fri Mar 3 11:52:44 EST 2006
Walter Dörwald wrote:
> I see: ipipe uses a new feature of eval() that makes it possible to pass
> a custom (non-dict) namespace. This makes it possible to directly
> reference the attributes of the object. For 2.3 compatibility I see
> several options:
> 1) Simply don't allow expression strings. This would only allow
> callables and
> iwalk | ifilter("name.endswith('.py')") | isort("size")
> would turn into
> iwalk | ifilter(lambda _:_.name.endswith('.py')) | isort(lambda _:_size)
> IMHO not so nice.
> 2) Pass a simple dictionary to eval() that just contains the object
> itself. The call would then look like this
> iwalk | ifilter("_.name.endswith('.py')") | isort("_.size")
> 3) Pass a dictionary that contains all the attributes from the list.
> This has the disadvantage that (for iwalk etc.) there will be many
> os.stat() calls, even if the result is never used (and you can't
> reference attributes that are not in the field list).
> BTW, the reason why you got an empty browser was, because ifilter
> ignores all objects where evaluating the expression raises and
> Exception. And then the expression for isort never fails, because
> there's nothing left to sort.
> Anyway, IMHO we should implement 2) and document the possibility to
> directly reference attributes as a "2.4 goodie".
That sounds like a good plan. 2.3 compatibility is important because a large
number of installed users still have that (Mac OSX and the 'enterprise'
versions of RedHat, amongst others) in their 'out of the box' configs. But
it's OK if a few extra conveniences are only available for 2.4 when they they
can't be implemented in a backport, as long as the basic functionality (like
the example in the docstring :) work with 2.3.
More information about the IPython-dev