以下是tornado如何使用MySQL:
from __future__ import print_function
from tornado import ioloop, gen
import tornado_mysql
@gen.coroutine
def f():
conn = yield tornado_mysql.connect(host='127.0.0.1', port=3306, user='user', passwd='passwd', db='mydb')
cur = conn.cursor()
yield cur.execute(query)
cur.close()
conn.close()
return cur
query = "select id from tablename"
for row in ioloop.IOLoop.current().run_sync(f):
print(row)
如果print(row)
执行零时间,则意味着select id from tablename
什么也得不到。
我只想知道如何立即获得ioloop.IOLoop.current().run_sync(f)
的大小(类似于ioloop.IOLoop.current().run_sync(f).size == 0
),以便确定某个sql查询是否获得了某些内容。你知道吗
在一个python序列上反复迭代一次,或者不迭代就知道序列中有多少东西是不可能的。为了安全起见,必须将结果复制到列表中:
相关问题 更多 >
编程相关推荐