[Python-ideas] SQL-like way to manipulate Python data structures

Aahz aahz at pythoncraft.com
Tue May 29 02:14:22 CEST 2007


On Mon, May 28, 2007, Steve Howell wrote:
> --- Aahz <aahz at pythoncraft.com> wrote:
>> 
>> What's wrong with sqlite?
> 
> Nothing, but I want Python itself to give me the SQL syntax to
> manipulate lists-of-dictionaries like lists of dictionaries, without
> having to go through some a module.
>
> In the example that I gave earlier in the thread, what would the
> sqlite solution look like?  To transform any particular list of
> dicitionaries into another list of dictionaries, would I have to do
> a create-table in sqlite, or does it already have some kind of mode
> where it can work directly on a Python dataset?

You'd have to convert your data into sqlite tables, of course, but:

* It's not much work

* Your specific needs for operating on data are likely to be different
from everyone else's -- the reason SQL works is precisely because it
imposes constraints on data format

To the extent that Python provides anything roughly comparable to SQL,
use listcomps and genexps.

Think of it this way: if Python requires you to use a library for regex
manipulation, what makes SQL-like data processing sufficiently special
that it belongs in the language itself?
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"Look, it's your affair if you want to play with five people, but don't
go calling it doubles."  --John Cleese anticipates Usenet



More information about the Python-ideas mailing list