我使用 MySql 创建了数据库并将排序规则设置为 utf8_unicode_ci。 我在 python 程序中查询数据,如下代码
db = MySQLdb.connect(host="localhost",user="root",passwd="password",db="database",charset="utf8",use_unicode=True)
cur = db.cursor()
cur.execute("select `name` from car_park where p_id=1" )
rows=cur.fetchall()
print(rows)
但输出是 u'\u0e40\u0e14\u0e2d\u0e30\u0e21\u0e2d\u0e25\u0e4c'。 实际上数据库中的数据源是泰语。其他人已经通过 python 从泰语数据库或其他 UTF-8 查询数据,请帮忙。 谢谢。
最佳答案
rows
似乎是一个列表,您应该对其进行迭代。
for row in rows:
print row
打印 unicode 对象不应出错。
关于Python:以UTF-8从Mysql查询数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33474221/