Python + MySQL + UTF-8

import MySQLdb as db
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
conn = db.connect(host="localhost", user="root",
                  passwd="", db="kulex",
                  use_unicode=True, charset="UTF8")
c = conn.cursor()
c.execute("SELECT * FROM `Classifier`")
while True:
    row = c.fetchone()
    if row == None:
        break
    for col in row:
        print col
c.close()
conn.close()

One thought on “Python + MySQL + UTF-8

ใส่ความเห็น

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / เปลี่ยนแปลง )

Twitter picture

You are commenting using your Twitter account. Log Out / เปลี่ยนแปลง )

Facebook photo

You are commenting using your Facebook account. Log Out / เปลี่ยนแปลง )

Google+ photo

You are commenting using your Google+ account. Log Out / เปลี่ยนแปลง )

Connecting to %s