Python:追加mysql结果

Python:追加mysql结果,python,mysql-python,Python,Mysql Python,这是我的剧本 import _mysql db=_mysql.connect("localhost","01","","z") db.query("select id from a limit 2") result = db.store_result() while True: record = result.fetch_row() if not record: break print record (执行和结果)是: 结果是正确的,但我希望它附加所有的结果,并

这是我的剧本

import _mysql

db=_mysql.connect("localhost","01","","z")

db.query("select id from a limit 2")

result = db.store_result()

while True:
    record = result.fetch_row()
    if not record: break
    print record
(执行和结果)是:

结果是正确的,但我希望它附加所有的结果,并简单地打印(基于上述输出)


您知道Python中的join函数吗?MySQL中还有一个group_concat函数,允许您直接在查询中执行此操作。@John Barça,我正在考虑将一个变量设置为空..&然后在循环中追加。variable=[]然后variable.append(record)?Sundar已经给了您这样的答案。如果可能的话,我总是喜欢在数据库中做事情,但这种方法会起作用。有没有理由不使用
import MySQLdb
以及它提供的功能?@glglgl,我使用的是MySQLdb,但是mysql结果中有恒定和随机的缓存。我没有找到有关如何关闭缓存的信息。切换到_mysql,问题就消失了。在行的末尾添加打印r,我认为你的意图是错误的,实际上工作正常。我错把印刷品缩进了r。
[root@ooo ~]# python a.py
(('1',),)
(('2',),)
[root@ooo ~]#
12
    import _mysql

db=_mysql.connect("localhost","sundar","","test")

db.query("select username from auth_user")

result = db.store_result()
r=""
while True:
    record = result.fetch_row()
    if not record: break
    elif record is None:break
    else:r+= record[0][0]
print r