1
如果我使用普通光標(即cur = con.cursor()
),此代碼適用於python3。python3使用fetchall和DictCursor的值
如果我想使用DictCursor
,該如何使此代碼正常工作? (即cur = con.cursor(mdb.cursors.DictCursor)
)
include numpy as np
import pymysql as mdb
--- cut ---
cur.execute("select id from history where category=%s;",("DATA"))
rows = cur.fetchall()
num_rows = int(cur.rowcount)
# recast this nested tuple to a python list and flatten it so it's a proper iterable:
x = map(list, list(rows)) # change the type
x = sum(x, []) # flatten
D = np.fromiter(iter=x, dtype=float, count=-1)
---
謝謝,這解決了我的問題:) – Intra