[Python-ideas] Accessing the result of comprehension's expression from the conditional

Mathias Panzenböck grosser.meister.morti at gmx.net
Sun Jun 21 03:51:28 CEST 2009


Chris Rebert wrote:
> On Fri, Jun 19, 2009 at 12:56 PM, Mathias
> Panzenböck<grosser.meister.morti at gmx.net> wrote:
>> Chris Rebert wrote:
>>> Comprehensions and generator expressions already give us most of the
>>> LINQ functionality. Add in `list()` and the ability to `.sort()` lists
>>> with a `key` argument and you have the entire thing, except for the
>>> one corner case being discussed. Unless I've overlooked something...
>> Yes: With LINQ its possible to build a query object out of an LINQ
>> expression instead of evaluating it eagerly. This is used primarily to
>> generate SQL code while still using syntax native to the host language (C#)
>> and preserving type safety (ok the later cannot be done in python).
> 
> One could probably hack that part together with lambdas, the ast
> module, and some black magic though.
> And are there any use cases besides SQL?

Yes: Queries on XML data. So you have the exact same Syntax for queries on 
simple lists, SQL databases and XML files (but yes, using LINGQ for XML is still 
much more to write than using something like XPath). I think you can also add 
your own backends if you like (e.g. for yaml?). And it's all native syntax (no 
limits on expressiveness and no problems concerning string escaping etc.).

	-panzi



More information about the Python-ideas mailing list