convert tuple to string

Anand Pillai pythonguy at Hotpop.com
Mon Aug 11 16:21:45 EDT 2003


Assuming 't' is your tuple of values,

print reduce(lambda x, y: x + ',' + y, map(lambda x: x[0], t))

will print a string with all first elements of the tuple
(your strings), separated by a comma.

-Anand 

Alex Martelli <aleax at aleax.it> wrote in message news:<sXNZa.39254$an6.1364884 at news1.tin.it>...
> Lukas Kasprowicz wrote:
> 
> > My Proglem is, I get after a query on a mysql database with module MySQLdb
> > a tuple but I need this output from database as a string.
> > can anybody help?
> 
> Sure!  Just bind that tuple, which you are currently returning, to a
> variable (so you can in fact close the connection -- you're not doing
> it now, since return ends your function), and then use that tuple as
> you prefer.  As it's a tuple of tuples you'll probably want to loop
> over it rather than just calling "//".join or whatever, of course.
> 
> Unless you know how you want to format the resulting string, it's
> unlikely that the result is going to be satisfactory to you, of course.
> 
> 
> Alex




More information about the Python-list mailing list