You could always make use of tuple-unpacking and try something like
[element for (element,) in cursor.fetchall()]
It feels slightly more pythonic to me, though not by much.
From: psycopg-owner(at)postgresql(dot)org [mailto:psycopg-owner(at)postgresql(dot)org] On Behalf Of W. Matthew Wilson
Sent: Tuesday, June 19, 2012 13:36
To: Daniele Varrazzo
Subject: Re: [psycopg] When I select a single column, can I prevent getting a list of one-element tuples?
On Sun, Jun 17, 2012 at 12:32 PM, Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com> wrote:
> No, there's nothing like this. For me, any attempt to add a feature
> and let the user choose whether to return one-column queries just as
> lists or as one-item tuples (a cursor subclass? a function?) seems
> more verbose than the [r for r in cur] or map(itemgetter(0), cur)
> to get the data the way you want.
Thanks for the reply! Mostly I wanted to make sure there wasn't already a standard solution out there.
For me, it just feels goofy to write something like [row for row in cursor.fetchall()], but I understand where you are coming from.
I like the cursor subclass idea so maybe I'll take a shot at something like that.
W. Matthew Wilson
Sent via psycopg mailing list (psycopg(at)postgresql(dot)org) To make changes to your subscription:
In response to
psycopg by date
|Next:||From: Federico Di Gregorio||Date: 2012-06-20 13:17:46|
|Subject: Re: Patches to add support for tox and Travis CI tools
|Previous:||From: W. Matthew Wilson||Date: 2012-06-19 18:36:11|
|Subject: Re: When I select a single column, can I prevent getting a
list of one-element tuples?|