[Tutor] tutorial for dbapi 2.0 how to use data (fwd)

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Tue May 11 17:30:51 EDT 2004

[Forwarding to Tutor: please make sure to keep Tutor at python.org in CC; if
I'm busy, we still want you to be able to get responses from the group.]

---------- Forwarded message ----------
Date: Tue, 11 May 2004 13:36:38 -0700
From: John Fabiani <jfabiani at yolo.com>
To: Danny Yoo <dyoo at hkn.eecs.berkeley.edu>
Subject: Re: [Tutor] tutorial for dbapi 2.0 how to use data

Danny Yoo wrote:

>On Tue, 11 May 2004, John Fabiani wrote:

>>mycur.execute("select * from sosord")
>>The above works and returns data.  But know I need to understand how to
>>view the data.  Maybe there is a way to convert the returned list into a
>>dictionary.  A dictionary would allow me to get information by key (the
>>field name).  Anyway, is there some paper or tutorial I can read on how
>>to view the return data?
>If you are using MySQLdb, then yes, there is a way of getting a customized
>cursor that returns dictionaries instead of tuples.  For example:
>>>>import MySQLdb.cursors
>>>>cursor = conn.cursor(cursorclass=MySQLdb.cursors.DictCursor)
>>>>cursor.execute("select * from pub_term where is_obsolete='n'")
>{'parentage': None, 'definition': 'A complex containing a heterodimer of a
>catalytic subunit and a regulatory (adaptor) subunit of any
>phosphoinositide 3-kinase (PI3K).', 'pub_object_id': 47030L,

[text cut]

This is a great first step!  I'm using the Postgres pgPySQL module.  How
can I tell if the module supports the cursors that MySQL supports?
description appears to return a tuple that contains tuples.  The first
column returns the field name - any chance you know what the other
columns mean?
So how do I setup the dictionary as in
{"id": 123, "go_external_id": 456, "name":"john", "type": "dumb",
"date_entered": 01/01/04 ...........}

The bottom line is I want to be able to access and change the data.
Isn't there some tutorial or something I can read that explains how this
is suppose to work?

I'd like to do things like the following:
loop thru the data
    make some test
         change some of the data in the current row/ list
 Save the data...
The above would be just normal database activities.....

More information about the Tutor mailing list