如何配置python mysql.connector以在没有bytearray b“”的情况下转换长文本字段

2024-09-27 19:19:05 发布

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

代码当前检查类型(bol)=bytearray,但如何让它对长文本列执行相同的操作?我试过使用pure=true/false以及raw=true/false。我已经安装了mysql python连接器8.0.6,运行python 3.5.4

对于longtext列,它将返回b'data'vs data

class MyConverter(mysql.connector.conversion.MySQLConverter):

    def row_to_python(self, row, fields):
        row = super(MyConverter, self).row_to_python(row, fields)

        def to_unicode(col):
            if type(col) == bytearray:
                return col.decode('utf-8')
            
            return col

        return[to_unicode(col) for col in row]

Tags: to代码selffalsetruefieldsdatareturn

热门问题