[Tutor] building a tuple

Darrell Brogdon dbrogdon@valinux.com
Thu, 15 Feb 2001 13:44:06 -0500


Well, I found that I could instead create a list and append to it using 
the extend() method and then convert the list into a tuple where I can 
work from there.

You're right about my confusion.  Here again, the line can be blurry 
sometimes in PHP. :)

Anyway, thanks for the help and sorry for the vague post.  When you're 
learning sometimes you don't quite know how to phrase your question.

Lindsay Davies wrote:

> 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. :)
>> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


-- 
Darrell Brogdon               http://darrell.brogdon.net
Web Developer - SourceForge   http://sourceforge.net
VA Linux Systems, Inc.        http://www.valinux.com