Ossama
Ossama

Reputation: 2433

Filter python mysql result

I am running a mysql query from python using mysql.connector library as per code below

cnx = mysql.connector.connect(host=mysql_localhost, user=user, password=password, database=database)
cursor = cnx.cursor()
cursor.execute("select  * from settings" )
results = cursor.fetchall()
ID, server, port, user, password, temp_min ,temp_max = results[0]
print(user)
cursor.close()
cnx.close()

the result is as follow

u'admin'

I noticed that values stored in the database as varchar display with u'' how can I get the value without the u'' so the desired output is

admin

Upvotes: 3

Views: 1002

Answers (3)

alecxe
alecxe

Reputation: 473863

u means that this is a unicode string. You should read Unicode HOWTO for better understanding.

Upvotes: 1

Robert Kajic
Robert Kajic

Reputation: 9077

The u in front of your variable means that it is a unicode string. Is that really a problem? If you really need to convert it to a regular string you can use str(user).

Upvotes: 0

jh314
jh314

Reputation: 27792

You can use str() to get rid of the u:

print str(user)

FYI-the u means it is unicode.

Upvotes: 0

Related Questions