Re: Select as dictionary...

2007-10-02 Thread Steve Holden
Abandoned wrote: > Also if i need a list id what can i do ? > > aia.execute("SELECT id, w from list") > links=aia.fetchall() > > I want to.. > > idlist=[1, 2, 3] ( I don't want to use FOR and APPEND because the > query have 2 million result and i want to speed) > It may not be practical for you

Re: Select as dictionary...

2007-10-02 Thread Duncan Booth
Abandoned <[EMAIL PROTECTED]> wrote: > ( I don't want to use FOR and APPEND because the > query have 2 million result and i want to speed) > How many times do you plan on doing this? On my system I just timed adding 2 million elements to a dictionary: it took 0.35 seconds. Appending 2 million

Re: Select as dictionary...

2007-10-01 Thread Carsten Haese
On Mon, 2007-10-01 at 10:13 -0700, Abandoned wrote: > Also if i need a list id what can i do ? > > aia.execute("SELECT id, w from list") > links=aia.fetchall() > > I want to.. > > idlist=[1, 2, 3] ( I don't want to use FOR and APPEND because the > query have 2 million result and i want to speed)

Re: Select as dictionary...

2007-10-01 Thread Diez B. Roggisch
Abandoned wrote: > Also if i need a list id what can i do ? > > aia.execute("SELECT id, w from list") > links=aia.fetchall() > > I want to.. > > idlist=[1, 2, 3] ( I don't want to use FOR and APPEND because the > query have 2 million result and i want to speed) It will always return a list of

Re: Select as dictionary...

2007-10-01 Thread Abandoned
Also if i need a list id what can i do ? aia.execute("SELECT id, w from list") links=aia.fetchall() I want to.. idlist=[1, 2, 3] ( I don't want to use FOR and APPEND because the query have 2 million result and i want to speed) -- http://mail.python.org/mailman/listinfo/python-list

Re: Select as dictionary...

2007-10-01 Thread Abandoned
On 1 Ekim, 18:13, Bruno Desthuilliers wrote: > J. Clifford Dyer a écrit : > > > On Mon, Oct 01, 2007 at 03:50:59PM +0200, Bruno Desthuilliers wrote > > regarding Re: Select as dictionary...: > >> IIRC, postgres' db-api connector (well, at least one of them - I

Re: Select as dictionary...

2007-10-01 Thread Bruno Desthuilliers
J. Clifford Dyer a écrit : > On Mon, Oct 01, 2007 at 03:50:59PM +0200, Bruno Desthuilliers wrote regarding > Re: Select as dictionary...: >> IIRC, postgres' db-api connector (well, at least one of them - I don't >> know which one you're using) has a DictCursor.

Re: Select as dictionary...

2007-10-01 Thread J. Clifford Dyer
On Mon, Oct 01, 2007 at 10:12:04AM -0400, Carsten Haese wrote regarding Re: Select as dictionary...: > > On Mon, 2007-10-01 at 09:57 -0400, J. Clifford Dyer wrote: > > > > > Try this: > > > > aia.execute("SELECT id, w from list") > > links=ai

Re: Select as dictionary...

2007-10-01 Thread Carsten Haese
> linkdict = dict(iter(aia.fetchone,None)) And by the way, that line can be shortened to "linkdict=dict(aia)" if the cursor object supports the iterator protocol, but that's not a mandatory feature in DB-API v2. The longer form is guaranteed to work with any DB-API v2 compliant implementation. --

Re: Select as dictionary...

2007-10-01 Thread Carsten Haese
On Mon, 2007-10-01 at 15:50 +0200, Bruno Desthuilliers wrote: > Besturk.Net Admin a écrit : > > I want to see this result directly as a dictionary: > > > > {1: 5, 2: 5 .} > > > > How do i select in this format ? > > IIRC, postgres' db-api connector (well, at least one of them - I don't > kn

Re: Select as dictionary...

2007-10-01 Thread J. Clifford Dyer
On Mon, Oct 01, 2007 at 03:50:59PM +0200, Bruno Desthuilliers wrote regarding Re: Select as dictionary...: > > IIRC, postgres' db-api connector (well, at least one of them - I don't > know which one you're using) has a DictCursor. You should find all you > want

Re: Select as dictionary...

2007-10-01 Thread Carsten Haese
On Mon, 2007-10-01 at 09:57 -0400, J. Clifford Dyer wrote: > On Mon, Oct 01, 2007 at 06:32:07AM -0700, Besturk.Net Admin wrote regarding > Select as dictionary...: > > > > aia.execute("SELECT id, w from list") > > links=aia.fetchall() > > print lin

Re: Select as dictionary...

2007-10-01 Thread Duncan Booth
"J. Clifford Dyer" <[EMAIL PROTECTED]> wrote: > aia.execute("SELECT id, w from list") > links=aia.fetchall() > linkdict = dict() > for k,v in links: > linkdict[k] = v > print linkdict Wouldn't it be simpler just to do: aia.execute("SELECT id, w from list") linkdict=dict(aia.fetchall())

Re: Select as dictionary...

2007-10-01 Thread Stargaming
On Mon, 01 Oct 2007 09:57:46 -0400, J. Clifford Dyer wrote: > On Mon, Oct 01, 2007 at 06:32:07AM -0700, Besturk.Net Admin wrote > regarding Select as dictionary...: >> >> aia.execute("SELECT id, w from list") links=aia.fetchall() >> print links >> &g

Re: Select as dictionary...

2007-10-01 Thread Tim Chase
> aia.execute("SELECT id, w from list") > links=aia.fetchall() > print links > > and result > [(1, 5), (2,5)...] (2 million result) > > I want to see this result directly as a dictionary: > > {1: 5, 2: 5 .} Because your fortuitously issued a select in that particular order (key, value)

Re: Select as dictionary...

2007-10-01 Thread M.-A. Lemburg
On 2007-10-01 15:32, Besturk.Net Admin wrote: > Hi.. > I am using python with postgresql. > And i have a query : > > aia.execute("SELECT id, w from list") > links=aia.fetchall() > print links > > and result > [(1, 5), (2,5)...] (2 million result) > > I want to see this result directly as a d

Re: Select as dictionary...

2007-10-01 Thread J. Clifford Dyer
On Mon, Oct 01, 2007 at 06:32:07AM -0700, Besturk.Net Admin wrote regarding Select as dictionary...: > > aia.execute("SELECT id, w from list") > links=aia.fetchall() > print links > > and result > [(1, 5), (2,5)...] (2 million result) > > I want to see

Re: Select as dictionary...

2007-10-01 Thread Bruno Desthuilliers
Besturk.Net Admin a écrit : > Hi.. > I am using python with postgresql. > And i have a query : > > aia.execute("SELECT id, w from list") > links=aia.fetchall() > print links > > and result > [(1, 5), (2,5)...] (2 million result) > > I want to see this result directly as a dictionary: > > {1

Select as dictionary...

2007-10-01 Thread Besturk.Net Admin
Hi.. I am using python with postgresql. And i have a query : aia.execute("SELECT id, w from list") links=aia.fetchall() print links and result [(1, 5), (2,5)...] (2 million result) I want to see this result directly as a dictionary: {1: 5, 2: 5 .} How do i select in this format ? I'm