本文實例展現了一個腳本python用來轉化表配置數據xml並生成相應的解析代碼。
可是在中文編碼上出現了亂碼,現將解決方法分享出來供你們參考。
具體方法以下:python
設置Python的默認編碼爲 utf-8 (sys.setdefaultencoding(utf-8)
示例代碼以下:
複製代碼 代碼以下:數據庫
import sys
import MySQLdb as mdbfetch
reload(sys)
sys.setdefaultencoding('utf-8')編碼
con = Nonecode
try:
con = mdb.Connect('localhost','root','jobin','zmld',charset='utf8')
cur = con.cursor()
cur.execute("show full columns from player")xml
numRows = int(cur.rowcount) for i in range(numRows): row = cur.fetchone() comment = row[len(row) - 1] print comment
finally:
if con:
con.close()utf-8