如何在 Python 中将元组转换为字符串? [英] How to convert a tuple to a string in Python?
本文介绍了如何在 Python 中将元组转换为字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 MySQL select 语句之后,我剩下以下内容:
After a MySQL select statement, I am left with the following:
set([('1@a.com',), ('2@b.net',), ('3@c.com',), ('4@d.com',), ('5@e.com',), ('6@f.net',), ('7@h.net',), ('8@g.com',)])
我想要的是一个
emaillist = "\n".join(queryresult)
到最后,有一个字符串:
to in the end, have a string:
1@a.com
2@b.net
3@c.com
etc
将此嵌套元组转换为字符串的正确方法是什么?
What would be the proper way to convert this nested tuple into string?
推荐答案
只要您确定每个元组只有一个元素:
As long as you're sure you have just one element per tuple:
'\n'.join(elem[0] for elem in queryresult)
这篇关于如何在 Python 中将元组转换为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文