import MySQLdb
db = MySQLdb.connect("localhost","root","password","database")
cursor = db.cursor()
cursor.execute("SELECT id FROM some_table")
u_data = cursor.fetchall()
>>> print u_data
((1320088L,),)
我找到了互联网上让我到这里:的Python:转换元组逗号分隔字符串
string = ((1320088L,),)
string = ','.join(map(str, string))
>>> print string
(1320088L,)
我所期望的输出看起来像:
#Single element expected result
1320088L
#comma separated list if more than 2 elements, below is an example
1320088L,1320089L
这个答案推广以及与长度元组> 1. – sirfz
不知道@Chris_Rands答案是一个更好的。这个答案和他的答案都适合我! – JackSparrow
@JackSparrow这些天itertools是扁平化列表或元组的推荐方式http://stackoverflow.com/questions/952914/making-a-flat-list-out-of-list-of-lists-in-python –