1
hahastudio 2013-08-20 18:18:33 +08:00
import MySQLdb
db = MySQLdb.connect( ... ) cur = db.cursor(MySQLdb.cursors.DictCursor) cur.execute('select * from test;') >>> cur.fetchone() {'a': 1L, 'c': 3L, 'b': 2L} |
2
kenneth OP @hahastudio 可能你没理解我的问题
|
3
hahastudio 2013-08-20 19:23:51 +08:00
@kenneth
>>> rows = cursor.fetchall() >>> for row in rows: >>> for row in rows: ... print row['a'], row['c'] ... 2 3 2 4 3 3 1 2 都字典了,该怎么按照 column name 访问不是很明确吗,一定要用namedtuple访问的话你构造一个呗= = 哦,顺带一提,我这列的名字就叫a, b, c= = |
4
SErHo 2013-08-20 19:42:05 +08:00
|
5
lj0014 2013-08-21 10:13:52 +08:00
row = result.fetch_row(how=1)[0]
row['a'] row['b'] ... |