Linq to Python

Duncan Booth duncan.booth at invalid.invalid
Thu Sep 25 04:08:08 EDT 2008


sturlamolden <sturlamolden at yahoo.no> wrote:

> On Sep 24, 10:59 pm, Duncan Booth <duncan.bo... at invalid.invalid>
> wrote:
> 
>> Simple LINQ expressions like the one you gave map easily to Python
>> list comprehensions. What Microsoft have done though is provide a
>> consistent implementation which allows you to write complex SQL like
>> expressions whi 
> ch
>> will work identically on databases or most other sequence types.
>> han extensions to syntax.
> 
> List comprehensions work with any iterable sequence. You can nest them
> to make more complex statements. You can also use a generator to
> iterate through a database or an XML document. Here is approximately
> where linq stops being a marvelous addition to Python.
> 
A lot of what LINQ does is already easy to do in Python, and most of the 
rest can probably be added fairly easily, but it does provide a consistent 
framework which may make it easier to do complex LINQ statements than 
complex list comprehensions.

BTW, a minor correction: LINQ statements are closer to generators, not list 
comprehensions. They don't actually evaluate their results until you 
iterate over them and you can re-used the same LINQ statement multiple 
times getting different results if the data has changed.

> And I can honestly do without the SQL syntax.
> 
snap :)

-- 
Duncan Booth http://kupuguy.blogspot.com



More information about the Python-list mailing list