[Tutor] building a tuple

Lindsay Davies Lindsay.Davies@moonshine.co.uk
Thu, 15 Feb 2001 08:15:54 +0000


Darrell -

I think I see where some of the confusion is coming from. The code 
snippet below  shows you building a dictionary (AKA hash or 
associative array), NOT a tuple, which is an immutable array.

If you are asking how do you build a dictionary from the result of a 
database query, then that is a different question from how to build a 
tuple.

The answer to dictionary-building does depend on the module you are 
using to access the database. For example, both the MySQLdb.py and 
PgSQL.py modules allow you to retrieve a dictionary (or 
dictionary-like object) from a *.fetchall() call for example. There 
is devil in the detail though, so perhaps you need to supply more 
information, like the database and DB API module you are using to 
access it.

Best wishes,

Lindsay



On 14/2/01, Darrell Brogdon wrote about 'Re: [Tutor] building a tuple':
>Ok, so for example, I'm getting the following data:
>
>Field Name        Value
>------------------------
>fname             John
>lname             Doe
>address           123 Any St.
>city              Anytown
>
>Now I know I can manually build a tuple out of this data with the following:
>
>    my_tuple {
>        "fname" : "John",
>        "lname" : "Doe",
>        "address" : "123 Any St."
>        "city" : "Anytown"
>    }
>
>But obviously with this data coming from the database I wouldn't 
>know what the values are.  I've figured out how to get the data out 
>of the database for the most part.  Now its just a matter of how to 
>get that data into a tuple.
>
>I think partly I'm confusing myself with my knowledge of PHP where 
>you can pretty much get away with anything. :)
>