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 –