簡體   English   中英

MySQLdb 不能使用游標類

[英]MySQLdb can't use cursorclass

我正在嘗試執行以下代碼:

import MySQLdb
import MySQLdb.cursors
conn=MySQLdb.connect(host = '127.0.0.1',
                     user = 'root',
                     passwd = 'root',
                     db = 'test',
                     cursorclass = MySQLdb.cursors.DictCursor)
cursor=conn.cursor()

但它給了我以下錯誤:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.linux-x86_64/egg/MySQLdb/connections.py", line 243, in cursor
  AttributeError: 'Connection' object has no attribute 'cursorclass'

為什么是這樣?

 import MySQLdb
 import MySQLdb.cursors
 conn=MySQLdb.connect(host = '127.0.0.1',
                         user = 'root', 
                         passwd = 'root',
                         db = 'test',)
cursor=conn.cursor(cursorclass = MySQLdb.cursors.DictCursor)

這是一個粗略的 hack,但可能不建議使用它。 默認情況下帶有拋出字典 object 的腳本,但應用程序可能需要元組或數組。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM