开发者

Does the MySQLdb module in python returns utf8 encoding or unicode in this case?

Using MySQLdb I connect to a database where everything is stored in the utf8 encoding.

If I do

cursor.execute("SET NAMES utf8")

and fetch some data from the database by another statement. Does that mean, that the strings in

cursor.execute("SELECT ...")
cursor.fetchall()

will be in unicode? Or do I have to turn them first by

mystr.decod开发者_JAVA技巧e("utf8")

to unicode?


From the docs:

connect(parameters...)
...

use_unicode

If True, CHAR and VARCHAR and TEXT columns are returned as Unicode strings, using the configured character set. It is best to set the default encoding in the server configuration, or client configuration (read with read_default_file). If you change the character set after connecting (MySQL-4.1 and later), you'll need to put the correct character set name in connection.charset.

If False, text-like columns are returned as normal strings, but you can always write Unicode strings.

This must be a keyword parameter.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜