【发布时间】:2011-11-10 19:15:33
【问题描述】:
我无法从 mysql 查询中获取 unicode 值。
这是我现在的做法:
>>> from MySQLdb import connect
>>> from MySQLdb.cursors import DictCursor
>>> con = connect(
passwd = "****",
db = 'my_db',
user = "db_user",
host = "localhost",
cursorclass = DictCursor,
use_unicode=True,
charset="utf8"
)
>>> cursor = con.cursor ()
>>> cursor.execute (u'Select * from basic_applet')
>>> res = cursor.fetchall()
>>> print(res)
({'Title_de': 'test title', .... })
>>> type(res[0]['Title_de'])
<type 'str'>
如您所见,它没有返回 unicode。
在我的表结构中,Title_de 设置为 unicode。
IDbasic_applet int(10)...
Title_de varchar(75) utf8_bin
我真的不知道自己做错了什么,非常欢迎任何帮助。
提前致谢,
西蒙
【问题讨论】:
标签: python mysql unicode mysql-python