[Python-ideas] proposal to add rowexpr as a keyword

George Sakkis george.sakkis at gmail.com
Tue May 29 17:03:38 CEST 2007


On 5/29/07, Blake Winton <bwinton at latte.ca> wrote:

> Steve Howell wrote:
> > Let the Python interpreter build expression objects
> > for you.  You write:
> >    rowexpr: convert_to_euros(salary) > 50000 and
> > deptno = 10
> > Python translates that into the same bytecode as:
> > lambda row: convert_to_euros(row['salary'] > 50000 and
> > row['deptno'] == 10
>
> I'm sorry, why would that not be translated into:
>
> lambda row: row['convert_to_euros'](row['salary'] > row['50000']
> row['and'] row['deptno'] == row['10']
>
> ?  Specifically, how would python know what to dereference and what not
> to?  What if there were two things, named the same, one in the row and
> one in the namespace?  (i.e. a variable named 'salary')  How would you
> escape things which would have been dereferenced but you didn't want to
> be?  (i.e. "rowexpr: convert_to_euros(salary) > salary")
>
> I guess I'm kind of wasting my time here, since the introduction of a
> new keyword for this application really isn't going to happen, based on
> other decisions I've seen Guido make, but I do think that you need to
> think a little more about how the implementation of this feature would
> work.  (Or perhaps you've done that thinking, and you just need to fill
> in the proposal with that information.)

Indeed, such half baked ideas have no chance of being taken seriously
as language additions. Take a look at packages such as buzhug [1] and
(especially) SqlAlchemy [2], not only because they might end up
solving your problem but also to appreciate the complexity involved in
supporting arbitrary SQL-like expressions at the language level, since
you clearly underestimate it or haven't quite thought about it.

George


[1] http://buzhug.sourceforge.net/
[2] http://www.sqlalchemy.org/docs/


-- 
"If I have been able to see further, it was only because I stood on
the shoulders of million monkeys."



More information about the Python-ideas mailing list