0

I created my database with MySql and set collation as utf8_unicode_ci. And I query data in python program as this code

db = MySQLdb.connect(host="localhost",user="root",passwd="password",db="database",charset="utf8",use_unicode=True)
cur = db.cursor()
cur.execute("select `name` from car_park where p_id=1" )
rows=cur.fetchall()
print(rows)

But the out put is u'\u0e40\u0e14\u0e2d\u0e30\u0e21\u0e2d\u0e25\u0e4c'. Actually the data source in database is Thai language. Anyone else have been query data from database in Thai language or another UTF-8 by python please help. Thanks.

1 Answer 1

1

rows seems to be a list and you should iterate over it.

for row in rows:
    print row

Printing a unicode object shouldn't make mistakes.

Sign up to request clarification or add additional context in comments.

2 Comments

@decltype_auto Well, As far as I tried, print u'\u0e40\u0e14\u0e2d\u0e30\u0e21\u0e2d\u0e25\u0e4c' always gives a Thai string. Thus I think Chin may have done print rows which prints [u'\u0e40\u0e14\u0e2d\u0e30\u0e21\u0e2d\u0e25\u0e4c']
@decltype_auto on the contrary. Compare print(u'\u0e40\u0e14\u0e2d\u0e30\u0e21\u0e2d\u0e25\u0e4c') with print([u'\u0e40\u0e14\u0e2d\u0e30\u0e21\u0e2d\u0e25\u0e4c']); the first shows the rendered text, the second shows the escape codes; because when you print a list, each element is shown with repr().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.