[Tutor] constructing tupples in 1.5.2

Lloyd Kvam pythontutor@venix.com
Sat, 16 Mar 2002 09:07:57 -0500


Untested code (and I do not have 1.5 to check against)
But it should be close.

Based on your message,  you probably have a list of dictionaries since
the keys are name, age and gender.  That implies one person per dictionary.

Possible working code:
insert_list = []
for d in dictionary_list:
	insert_list.append( (d[name], d[age], d[gender]) )


Pijus Virketis wrote:

> Dear all,
> 
>  
> 
> I am writting a MySQL script, which will be deployed on Py1.5.2. The 
> call to the database made through MySQLdb module must be in the form of 
> a list of tupples (e.g. [("John", 33, "M"), ("Sally", 35, "F"), ...]. 
> The thing is, I need to construct these tupples on the fly: I have a 
> dictionary of values (e.g. {"name": "John", "age": 33, ... }) and I want 
> to put the right values in the right places in a tupple. In Py2.2 this 
> is easy, because the tupple object has a handy __add__ method, which 
> concatenates two tupples. Py1.5.2, unfortunately, does not support this 
> method. What would be the most effective way of doing this? A workaround 
> I have though of is updating the table entry-by-entry, rather than 
> making one big update call, but it's obviously less efficient to run all 
> these INSERT querries.
> 
>  
> 
> Cheers,
> 
>  
> 
> Pijus
> 
>  
> 
>  
> 
> 
> ----------------------------
> Nothing is as simple as it seems at first Or as hopeless as it seems in 
> the middle Or as finished as it seems in the end. - /usr/games/fortune
> 


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice: 
603-443-6155
fax: 
801-459-9582