Python Forum

Full Version: PyMySQL
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey,

I have PyMySQL working however the result its printing has an unexpected character.

#!/usr/bin/python

import pymysql.cursors

connection = pymysql.connect(
    host='localhost',
    user='test',
    password='test',
    db='test',
    charset='utf8',
    cursorclass=pymysql.cursors.DictCursor
)

try:
    with connection.cursor() as cursor:
        cursor.execute("SELECT * FROM `test` WHERE `id`=`1`")
        result = cursor.fetchone()
        print(result)

finally:
    connection.close()
These are the results i get.

{u'row1': 100, u'row2': 100}

All of the results i get have a u before each result. I could always just cut up the string but i was more so wondering what the u means.

Thanks
It's unicode. The u isn't actually part of your string, much like a bracket character isn't part of a list.