如何确定mysql.connector游标类型?

2024-06-24 13:25:47 发布

您现在位置:Python中文网/ 问答频道 /正文

这个python代码中发生了什么? 如果按图所示执行,它将打印“MySQLCursor”。 如果我注释掉“import hashlib”,它将打印“CMySQLCursor”。 我有一些导入hashlib的代码,也有一些不导入hashlib的代码,但我希望一致地正确检测游标类型

“C”是什么意思?它的起源是什么

以下是可能的游标类型(带有或带有C前缀,具体取决于hashlib的存在):

  • CMySQLCursor
  • CMySQLCursorBuffered
  • CMySQLCursorRaw
  • CMySQLCursorBufferedRaw
  • CMYSQLCURSORDCT
  • CMYSQLCURSORBFEREDDICT
  • CMySQLCursorNamedTuple
  • CMySQLCursorBufferedNamedTuple
  • CMySQLCursorPrepared
import hashlib
import mysql.connector  

db = mysql.connector.connect(user='myuser', password='mypass', host='myhost', database='myschema')
cursor = db.cursor()

print (type(cursor).__name__) 

Tags: 代码import类型dbconnectormysqlcursorhashlib