This example shows a script python used to convert the table configuration data XML and generate the corresponding parsing code.
But in the Chinese code on the emergence of garbled, the solution is to share out for everyone's reference.
The specific methods are as follows:
1. python File Set encoding Utf-8 (#encoding =utf-8 before file)
2. mysql Database charset=utf-8
3. Python connection MySQL is a plus parameter Charset=utf8
4. Set the default encoding for Python to Utf-8 (sys.setdefaultencoding (Utf-8)
The sample code is as follows:
Copy Code code as follows:
#encoding =utf-8
Import Sys
Import MySQLdb as MDB
Reload (SYS)
Sys.setdefaultencoding (' Utf-8 ')
con = None
Try
Con = mdb. Connect (' localhost ', ' root ', ' jobin ', ' zmld ', charset= ' UTF8 ')
cur = con.cursor ()
Cur.execute ("Show all columns from player")
numrows = Int (cur.rowcount)
For I in Range (NumRows):
row = Cur.fetchone ()
Comment = Row[len (row)-1]
Print Comment
Finally
If con:
Con.close ()
I hope this article will help you with your Python programming.