Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a tuple to a string in Python?

Tags:

python

tuples

After a MySQL select statement, I am left with the following:

set([('[email protected]',), ('[email protected]',), ('[email protected]',), ('[email protected]',), ('[email protected]',), ('[email protected]',), ('[email protected]',), ('[email protected]',)])

What I would like to have is a

emaillist = "\n".join(queryresult)

to in the end, have a string:

[email protected]
[email protected]
[email protected]
etc

What would be the proper way to convert this nested tuple into string?

like image 442
Cmag Avatar asked Nov 30 '22 07:11

Cmag


1 Answers

As long as you're sure you have just one element per tuple:

'\n'.join(elem[0] for elem in queryresult)
like image 163
Daniel Roseman Avatar answered Dec 05 '22 02:12

Daniel Roseman