中文乱码问题,请高手解答!!!
#-*- coding:utf-8 -*- import MySQLdb conn = MySQLdb.Connect( host = '127.0.0.1', user = 'root', #密码部分处于隐私就这样表示一下 passwd = ******, port = 3306, db = 'imooc', charset = 'utf8' ) cursor = conn.cursor() sql = "SELECT * FROM tdb_goods" cursor.execute(sql) print cursor.rowcount rs = cursor.fetchone() #中文可以正常显示 print 'goods_id:%d, goods_name:%s'%(rs[0], rs[1]) #中文不能正常显示 print rs cursor.close() conn.close()
代码如上,显示的结果如下:
C:\Python27\python.exe C:/LearnPython/MySQL_Python/CursorTest.py
21
goods_id:1, goods_name:R510VC 15.6英寸笔记本
(1, u'R510VC 15.6\u82f1\u5bf8\u7b14\u8bb0\u672c', 5, 2, Decimal('3399.000'), 1, 0)
Process finished with exit code 0
那么,为什么
print 'goods_id:%d, goods_name:%s'%(rs[0], rs[1])
可以正常显示中文,而
print rs
不行呢???