Linq to Python

r0g aioe.org at technicalbloke.com
Wed Sep 24 16:09:55 EDT 2008


bearophileHUGS at lycos.com wrote:
> sturlamolden:
>> No, because Python already has list comprehensions and we don't need the XML buzzword.<
> 
> LINQ is more than buzzwords. Python misses several of those features.
> So maybe for once the Python crowd may recognize such C# feature as
> much better than things present in Python.
> Said that, I presume Python will go on as usual, and LINQ-like
> capabilities will not be integrated in Python. In the meantime where I
> live lot of people will keep using C# instead of Python and CLisp,
> natural selection at work indeed.
> 
> Bye,
> bearophile

LOL, I just read that and thought - Ok this sounds serious I'd better go
 find out what this LINQ business is all about so I googled.. and ended
up on MSDN where there's impressive sounding talk about how we need a
way to query databases and XML files with a unified syntax like we do
for for standard datatypes like files and arrays. Well yes,that makes
sense I think and proceed to look at their example code, curious as to
what this new paradigm looks like:

using System;
using System.Linq;
using System.Collections.Generic;

class app {
  static void Main() {
    string[] names = { "Burke", "Connor", "Frank",
                       "Everett", "Albert", "George",
                       "Harris", "David" };

    IEnumerable<string> query = from s in names
                               where s.Length == 5
                               orderby s
                               select s.ToUpper();

    foreach (string item in query)
      Console.WriteLine(item);
  }
}

ROTFLMAO! Wow, what progress they're making! Quick guys let's jump on
before we get left behind - we dont want to miss out on this exciting
and mysterious 'foreach' construct or this strange and exotic sounding
'IEnumerable query' thing. To think that python might someday reach such
lofty heights where we'll be able to simply write...

names = ["Burke", "Connor", "Frank", "Everett",
         "Albert", "George", "Harris", "David"]

result = [each.upper() for each in names if len(each) == 5]

result.sort()

for each in result: print each


Yes clearly 'the Python crowd' must admit LINQ is 'much better', I'm
sold, in fact off to download my "Free, but limited editions of Visual
Studio 2005 for a single programming language supported by .NET" right away!

OK so maybe I'm being naive here but it looks to me like this new
paradigm's big idea is to use a python + SQL type syntax to access data
in random objects. Big whoop. It's not that difficult to write a
generators that wraps XML files and databases is it?

What am I missing here?


Roger Heathcote.



More information about the Python-list mailing list