这是如何运作的?我查过文档。它说 cursor.rowfactory 是一个属性,让用户定义如何检索行的格式。但是我没有看到任何如何定义它的示例。然后我就找到了上面的答案。我完全迷失了方向,不知道那是做什么的。谁能解释一下那是做什么的? .rowfactory
属性是什么? makeDictFactory 是如何工作的? createRow
正在做什么以及 args
包含什么?
有什么文件可以查吗?
def makeDictFactory(cursor):
columnNames = [d[0] for d in cursor.description]
def createRow(*args):
return dict(zip(columnNames, args))
return createRow
curs.rowfactory = makeDictFactory(curs)
curs.fetchone()
最佳答案
看例子https://github.com/oracle/python-cx_Oracle/blob/master/samples/GenericRowFactory.py
另请查看 cx_Oracle 教程 https://github.com/oracle/python-cx_Oracle/tree/master/samples/tutorial
另请参阅有关 cx_Oracle 的演示文稿,如 https://static.rainfocus.com/oracle/oow18/sess/1523651275582001fu8I/PF/TIP4076%20-%20Python%20and%20Oracle%20Database%20on%20the%20Table_1540587368635001aNOw.pdf
关于python - cursor.rowfactory (cx_oracle) 如何以字典格式返回每一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53249527/