【发布时间】:2020-03-04 22:07:20
【问题描述】:
我尝试从 py manage.py shell 加载数据
使用此代码
def makeDictFactory(cursor):
columnNames = [d[0] for d in cursor.description]
def createRow(*args):
return dict(zip(columnNames, args))
return createRow
import cx_Oracle
dsn_tns = cx_Oracle.makedsn('', '', sid='')
conn = cx_Oracle.connect(user=r'', password='', dsn=dsn_tns)
c = conn.cursor()
c.execute("select table_name from all_tables")
c.rowfactory = makeDictFactory(c)
c.fetchall()
我想要的输出是 { a : b , c : d} ,但是当我执行 c.fetchall() 时它变成 [{a:b},{c:d}] ,当我放后端的代码想要显示到前端,它会返回一个错误,比如 unhashable type dict , unhashable type list or context must dict or list
我该怎么办?
【问题讨论】: