convert tuple to string

Alex Martelli aleax at aleax.it
Mon Aug 11 10:42:32 EDT 2003


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