本文介绍了Python Mysqldb 返回问号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我在 python 中使用以下代码,它似乎将名称"作为问号返回,因为名称是俄语.任何帮助将非常感激.

I am using the following code in python and it seems to be returning the "Name" as question marks since the name is in russian. Any help would be much appreciated.

import MySQLdb
db = MySQLdb.connect(host="localhost", user="root",passwd="*****")
cur = db.cursor()
cur.execute("USE WebCorpusStatus;")
cur.execute("SELECT Name, Source, Date(dateScraped) FROM russian WHERE status = 1;")
for row in cur:
    print row

推荐答案

MySQLdb.connect 带一个 use_unicode 参数,可以解决问题.如果没有,您可能还需要将字符集设置为您的表使用的任何内容:

MySQLdb.connect takes a use_unicode parameter, which may solve the problem. If not, you may also need to set charset to whatever your table uses:

MySQLdb.connect(host="localhost", user="root",passwd="*****", use_unicode=True, charset='xxxxx')

http://mysql-python.sourceforge.net/MySQLdb.html

这篇关于Python Mysqldb 返回问号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 20:31