小编Jac*_*row的帖子

Python:将元组转换为逗号分隔的String

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,),)
Run Code Online (Sandbox Code Playgroud)

我在互联网上找到的东西让我直到这里:

string = ((1320088L,),)
string = ','.join(map(str, string))
>>> print string
(1320088L,)
Run Code Online (Sandbox Code Playgroud)

我期望输出看起来像:

 #Single element expected result
 1320088L  
 #comma separated list if more than 2 elements, below is an example
 1320088L,1320089L
Run Code Online (Sandbox Code Playgroud)

python mysql string tuples python-2.x

4
推荐指数
2
解决办法
4801
查看次数

标签 统计

mysql ×1

python ×1

python-2.x ×1

string ×1

tuples ×1